|
-
Nov 13th, 2000, 07:08 PM
#1
Thread Starter
The picture isn't missing
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
-
Nov 13th, 2000, 07:16 PM
#2
Here you go:
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
[Edited by Matthew Gates on 11-13-2000 at 07:18 PM]
-
Nov 13th, 2000, 07:19 PM
#3
Thread Starter
The picture isn't missing
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
Nov 13th, 2000, 07:22 PM
#4
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
-
Nov 13th, 2000, 07:31 PM
#5
Thread Starter
The picture isn't missing
doesnt work. what am i doing wrong
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
Nov 13th, 2000, 07:47 PM
#6
When you let go of the mouse, it snaps back into place.
-
Nov 13th, 2000, 08:02 PM
#7
Thread Starter
The picture isn't missing
Remember, if someone's post was not helpful, you can always rate their post negatively  .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|