How can I allow a user to move a form but prevent the form from being placed outside the screen area.
I do not want my application to be out of sight of they need to move it around a little.
Anyone have an idea?
Thanks for reading this.
Printable View
How can I allow a user to move a form but prevent the form from being placed outside the screen area.
I do not want my application to be out of sight of they need to move it around a little.
Anyone have an idea?
Thanks for reading this.
Try this:
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
frm.Refresh
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
I gave the code a try but had not luck. Must be too early in the morning for me. Can you tell me how to make this work properly?
I have a project due today for review so I am limited on time to mess around with it.
Thanks for your assistance.
Code:Option Explicit
'you could do it this way / add a timer control
Private Sub Form_Load()
Timer1.Interval = 1
End Sub
Private Sub Timer1_Timer()
If ((Form1.Left) < 0) Then Form1.Left = 0
If ((Form1.Top) < 0) Then Form1.Top = 0
If ((Form1.Left) > Screen.Width - Form1.Width) _
Then Form1.Left = Screen.Width - Form1.Width
If ((Form1.Top) > Screen.Height - Form1.Height) _
Then Form1.Top = Screen.Height - Form1.Height
End Sub
That is a good option... I can use if necessary.. :)
But do not think they will move the form around enough to do that. LOL I am hoping to have a way to do it thru the system itself.