how do I make the form always on the screen? so like if i move it to the edge, it wont go over the edge. like a PayForSurf Bar
Printable View
how do I make the form always on the screen? so like if i move it to the edge, it wont go over the edge. like a PayForSurf Bar
Here you go:
[Edited by Matthew Gates on 11-13-2000 at 07:18 PM]Code:Public Declare Sub ReleaseCapture Lib "user32" ()
Public Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As _
Long, ByVal wParam As Long, lParam As Any) As Long
Public Sub FormMove(frm As Form)
ReleaseCapture
SendMessage frm.hwnd, &H112, &HF012, 0
If frm.Left < 0 Then 'left side of screen
frm.Left = 0
If frm.Top < 0 Then
frm.Top = 0
ElseIf frm.Top > Screen.Height - frm.Height Then
frm.Top = Screen.Height - frm.Height
End If
ElseIf frm.Top < 0 Then 'top of screen
frm.Top = 0
If frm.Left < 0 Then
frm.Top = 0
ElseIf frm.Left > Screen.Width - frm.Width Then
frm.Left = Screen.Width - frm.Width
End If
ElseIf frm.Left > Screen.Width - frm.Width Then 'right of screen
frm.Left = Screen.Width - frm.Width
If frm.Top < 0 Then
frm.Top = 0
ElseIf frm.Top > Screen.Height - frm.Height Then
frm.Top = Screen.Height - frm.Height
End If
ElseIf frm.Top > Screen.Height - frm.Height Then 'bottom of screen
frm.Top = Screen.Height - frm.Height
If frm.Left < 0 Then
frm.Top = 0
ElseIf frm.Left > Screen.Width - frm.Width Then
frm.Left = Screen.Width - frm.Width
End If
End If
End Sub
Usage
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call FormMove(Me)
End Sub
thanx ill try that
If you don't want to use a Module, change Public to Private.
Code:Private Declare Sub ReleaseCapture Lib "user32" ()
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As _
Long, ByVal wParam As Long, lParam As Any) As Long
Private Sub FormMove(frm As Form)
ReleaseCapture
SendMessage frm.hwnd, &H112, &HF012, 0
If frm.Left < 0 Then 'left side of screen
frm.Left = 0
If frm.Top < 0 Then
frm.Top = 0
ElseIf frm.Top > Screen.Height - frm.Height Then
frm.Top = Screen.Height - frm.Height
End If
ElseIf frm.Top < 0 Then 'top of screen
frm.Top = 0
If frm.Left < 0 Then
frm.Top = 0
ElseIf frm.Left > Screen.Width - frm.Width Then
frm.Left = Screen.Width - frm.Width
End If
ElseIf frm.Left > Screen.Width - frm.Width Then 'right of screen
frm.Left = Screen.Width - frm.Width
If frm.Top < 0 Then
frm.Top = 0
ElseIf frm.Top > Screen.Height - frm.Height Then
frm.Top = Screen.Height - frm.Height
End If
ElseIf frm.Top > Screen.Height - frm.Height Then 'bottom of screen
frm.Top = Screen.Height - frm.Height
If frm.Left < 0 Then
frm.Top = 0
ElseIf frm.Left > Screen.Width - frm.Width Then
frm.Left = Screen.Width - frm.Width
End If
End If
End Sub
Usage
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call FormMove(Me)
End Sub
doesnt work. what am i doing wrong
When you let go of the mouse, it snaps back into place.
oh. okay thanx