473,472 Members | 2,257 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Detecting form movement

Is there an event triggered when a form is dragged by its titlebar?

I have two forms on screen - the main form is draggable and I need the
secondary form to automatically reposition itself adjacent to the main form
if the main form is relocated.

Tom
Jul 17 '05 #1
2 2636

"Kiteman - Canada" <-d*************@shaw.ca> wrote in message
news:sNxjc.271888$Pk3.212594@pd7tw1no...
Is there an event triggered when a form is dragged by its titlebar?

I have two forms on screen - the main form is draggable and I need the
secondary form to automatically reposition itself adjacent to the main form if the main form is relocated.

Tom

Without subclassing the window, all I can think of is save Me.left and
me.top on form activate.

Have a timer event that checks If Me.Left <> oldleft Or Me.Top <> oldtop
Then <form has been moved>

Jul 17 '05 #2
Raoul, thanks for the reply. I tried your timer method and it works like a
charm. I wanted the repositioning of the second form to happen quicker, so
I turned down the Interval on the timer from 500 down to 20 and was unhappy
with the CPU intensity....so....

I made the Main form non-draggable and created a text lbl called lblDragForm
on the form called 'Main' and I can just left or right click and hold on
that label. I then created the following code:

Public Sub lblDragForm_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
'When left mouse button is pressed over Drag box enable dragging
MoveTheForm = True ' Drag is enabled
'Locate where on the Drag box the user has clicked and remember that
position for the lblDragForm routine
StartX = X
StartY = Y
End Sub

Public Sub lblDragForm_MouseUp(Button As Integer, Shift As Integer, X As
Single, Y As Single)
'When left mouse button is released stop the drag and force form to be
within screen borders
MoveTheForm = False ' Drag is disabled
If Main.Left < 0 Then Main.Left = 0
If Main.Top < 0 Then Main.Top = 0
If Main.Top + Main.Height > Screen.Height Then _
Main.Top = Screen.Height - Main.Height
If Main.Left + Main.Width > Screen.Width Then _
Main.Left = Screen.Width - Main.Width
Call RefreshVisibleForm
End Sub

Public Sub lblDragForm_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
'This routine loops while LMB is depress over the Drag box and the mouse is
moved
If MoveTheForm Then
Main.Left = Main.Left - StartX + X
Main.Top = Main.Top - StartY + Y
Call RefreshVisibleForm
End If
End Sub
Private Sub RefreshVisibleForm()
Select Case ComboMenu.ListIndex
Case 0
frmIntroduction.Top = Main.Top + VerticalOffset
frmIntroduction.Left = Main.Left
frmIntroduction.Show
Case 1
frmMaterialsRequired.Top = Main.Top + VerticalOffset
frmMaterialsRequired.Left = Main.Left
frmMaterialsRequired.Show
Case 2
frmGettingStarted.Top = Main.Top + VerticalOffset
frmGettingStarted.Left = Main.Left
frmGettingStarted.Show

<snip>

End Select
End Sub

This is an unconvential way of dragging a form, but if it works, why not!

Tom

"Raoul Watson" <Wa*****@IntelligenCIA.com> wrote in message
news:cD*******************@nwrdny03.gnilink.net...

"Kiteman - Canada" <-d*************@shaw.ca> wrote in message
news:sNxjc.271888$Pk3.212594@pd7tw1no...
Is there an event triggered when a form is dragged by its titlebar?

I have two forms on screen - the main form is draggable and I need the
secondary form to automatically reposition itself adjacent to the main

form
if the main form is relocated.

Tom

Without subclassing the window, all I can think of is save Me.left and
me.top on form activate.

Have a timer event that checks If Me.Left <> oldleft Or Me.Top <> oldtop
Then <form has been moved>

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Nomen Nescio | last post by:
can anyone be so kind as to look at http://www.mysolution.ws/HYPOCRITE.php and let me know why it isn't passing the form data to http://www.mysolution.ws/insertHYPOCRITES.php for the most...
3
by: raptor | last post by:
hi, how to detect opera..it seems that even opera8 doesnt support xmlhttp fully (.i.e. sendRequestHeader). I ask this 'cause opera seems to mimic IE, at least in the preferences ?! I havent...
1
by: Rocky A | last post by:
I don't remember ever reading about this in any of the "how to" books I've got or I wouldn't bother you guys (honest, I'm not being lazy here.....OK maybe just a little, but you guys are SOOOO...
1
by: John | last post by:
Hi all: I have an application that hides itself and displays an icon in the system tray. Is it possible for this application to detect keystrokes and/or mouse movements while hidden/minimized....
27
by: Deek | last post by:
I have a target(graphic) that moves via, i am trying to detect a hit of the target with and essay(copied below) my prof gave us, but I am not sure what to do, if you could get me going in the...
1
by: Lloyd Sheen | last post by:
I have the following situation: Need a user resizable user control. After much trying with user control I came across the idea of hosting the controls in a form marked as not TopLevel = false. ...
1
by: Dean Slindee | last post by:
In my application there is a main form with a tabcontrol. On each page in the tabcontrol is a panel upon which is painted a "sub" form. The main form acts as the "application host", while the...
13
by: robert | last post by:
My code does recursion loops through a couple of functions. Due to problematic I/O input this leads sometimes to "endless" recursions and after expensive I/O to the Python recursion exception. What...
1
by: wwwords | last post by:
Is there a general method for detecting that a user has changed the record currently visible on a form, whether this is by hitting PgUp or PgDn or clicking on a navigation button, even if no change...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.