|
-
Sep 6th, 2000, 09:45 PM
#1
Thread Starter
Hyperactive Member
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.
-
Sep 6th, 2000, 09:49 PM
#2
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
-
Sep 7th, 2000, 05:40 AM
#3
Thread Starter
Hyperactive Member
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.
-
Sep 7th, 2000, 06:23 AM
#4
_______
<?>
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
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 7th, 2000, 06:46 AM
#5
Thread Starter
Hyperactive Member
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.
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
|