|
-
Jun 18th, 2006, 02:25 AM
#1
Thread Starter
Lively Member
How to detect the VB Form is moved and Resizing of Form is complete?
Hello!
Currently, I'm working on a Website Sticky Notes Desktop Assistant application. The Application resides in System Tray and user clicks on it to get the Compose Note Interface. There are certain Ajax APIs to register the Position and Size of Note Window. I need to syncronize the size and location of Note window on User's Desktop with Online MySQL database. I'm facing problem in detecing Form Resize and change of Form position.
The Resize event of Form is fired everytime a slightest resize action is taken. However, I can not execute XMLHTTP so fast and so many times! So, I was wondering why Microsoft has not given any event such as Resizing and ResizeComplete. Is there any API trick or some windows subclassing trick which will help me to mimic Resize complete? When User moves his mouse to the edge of form and then clicks mouse button to start resize; then just keeps on moving his mouse and several times Form_Resize() event is fired! I thought that Form MouseUp() will be available once user releases his mouse but no luck! Any suggestion/work-around for this?
Second problem is even more interesting! There is no default event for VB Form which will show that Form Position is changed, is there any? How to detect that the Form is moved? I'm not finding any specific API or not that familiar with Windows Messages to subclass the event. Please help me to resolve this issue.
Eagerly waiting for your reply ...
Regards,
Ruturaj.
-
Jun 18th, 2006, 02:57 AM
#2
Re: How to detect the VB Form is moved and Resizing of Form is complete?
Here's a simple way to do it without subclassing. You need to put a Timer control on your form and set its Interval property to something fairly small, eg 200
VB Code:
Option Explicit
Dim IsLoading As Boolean
Dim FormHasResized As Boolean
Dim FormHasMoved As Boolean
Dim orgLeft As Single
Dim orgTop As Single
Private Sub Form_Activate()
orgLeft = Me.Left
orgTop = Me.Top
IsLoading = False
End Sub
Private Sub Form_Load()
IsLoading = True
End Sub
Private Sub Form_Resize()
If IsLoading Then Exit Sub
FormHasResized = True
End Sub
Private Sub Timer1_Timer()
If (Me.Left <> orgLeft) Or (Me.Top <> orgTop) Then
MsgBox "Form has been moved"
FormHasMoved = True
orgLeft = Me.Left
orgTop = Me.Top
End If
If FormHasResized Then
MsgBox "Form has been resized"
FormHasResized = False
End If
End Sub
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Jun 18th, 2006, 03:35 AM
#3
Thread Starter
Lively Member
Re: How to detect the VB Form is moved and Resizing of Form is complete?
 Originally Posted by pnish
Here's a simple way to do it without subclassing. You need to put a Timer control on your form and set its Interval property to something fairly small, eg 200
VB Code:
Option Explicit
Dim IsLoading As Boolean
Dim FormHasResized As Boolean
Dim FormHasMoved As Boolean
Dim orgLeft As Single
Dim orgTop As Single
Private Sub Form_Activate()
orgLeft = Me.Left
orgTop = Me.Top
IsLoading = False
End Sub
Private Sub Form_Load()
IsLoading = True
End Sub
Private Sub Form_Resize()
If IsLoading Then Exit Sub
FormHasResized = True
End Sub
Private Sub Timer1_Timer()
If (Me.Left <> orgLeft) Or (Me.Top <> orgTop) Then
MsgBox "Form has been moved"
FormHasMoved = True
orgLeft = Me.Left
orgTop = Me.Top
End If
If FormHasResized Then
MsgBox "Form has been resized"
FormHasResized = False
End If
End Sub
Hmm, interesting solution! It looks perfect for Form Moved. But, I think with Form Resize, I will face the same trouble as I do with Form_Resize() event. It will be thrown several times. Add Debug.Print to Resize event and resize Form by holding edge of Form and moving mouse continuously by holding left-mouse button. See, how many times you get the Debug text printed in your immediate window! Actually, that many time XMLHTTP will be executed!!! Will that be a wise implementation?!?! I'm looking for some work-around for this. Any suggestion?
-
Jun 18th, 2006, 05:51 AM
#4
Re: How to detect the VB Form is moved and Resizing of Form is complete?
here's a simple way to get a 'finished resizing' event:
VB Code:
Private Sub Form_Resize()
Timer1.Enabled = False
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
RedrawForm
Timer1.Enabled = False
End Sub
Private Sub RedrawForm()
' Place your 'Finished Resizing' code here
Debug.Print "Redraw"
End Sub
Set the timer interval to something like 500
-
Jun 18th, 2006, 09:05 AM
#5
Thread Starter
Lively Member
Re: How to detect the VB Form is moved and Resizing of Form is complete?
 Originally Posted by bushmobile
here's a simple way to get a 'finished resizing' event:
VB Code:
Private Sub Form_Resize()
Timer1.Enabled = False
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
RedrawForm
Timer1.Enabled = False
End Sub
Private Sub RedrawForm()
' Place your 'Finished Resizing' code here
Debug.Print "Redraw"
End Sub
Set the timer interval to something like 500
Yeh! Great trick! it works. I changed the Interval to something like 1500 and it worked smooth without any load on XMLHTTP object. How about Form Move? Right now, I've implemented the same trick of timer checking the Left and Top of Form; if different then I send change Position XMLHTTP to Server. Any better solution on this? By the way, I'm happy to see that I'm able to avoid subclassing (which is not at all VB IDE friendly!) and it has become possible only because of your valuable tricks. Please let me know if there is any work-around for Form Move. WM_MOVE is fired when Form Move is FINISHED; right?
-
Jun 18th, 2006, 11:11 AM
#6
Re: How to detect the VB Form is moved and Resizing of Form is complete?
Here you go - same principle as with the code in post #4 (in my testing both timer intervals were set to 500):
VB Code:
Private lOldX As Long, lOldY As Long
Private bCheck As Boolean
'======================
' MoveFinished Code
'----------------------
Private Sub Form_Load()
lOldX = Me.Left
lOldY = Me.Top
End Sub
Private Sub tmrMove_Timer()
If Me.Left = lOldX And Me.Top = lOldY Then
If bCheck Then
MoveFinished
bCheck = False
End If
Else
lOldX = Me.Left
lOldY = Me.Top
bCheck = Not tmrDraw.Enabled
End If
End Sub
Private Sub MoveFinished()
Debug.Print "Move Finished " & Rnd
End Sub
'======================
' ResizeFinished Code
'----------------------
Private Sub Form_Resize()
tmrDraw.Enabled = False
tmrDraw.Enabled = True
End Sub
Private Sub tmrDraw_Timer()
ResizeFinished
tmrDraw.Enabled = False
End Sub
Private Sub ResizeFinished()
Debug.Print "Resize Finished " & Rnd
End Sub
WM_MOVE event is fired once the form has finished moving - WM_MOVING is fired as it moves.
WM_SIZE for finished sizing.
Subclassing would be the standard (and best) way of doing this - but if you don't feel confident subclassing then using timers is an option.
-
Jun 18th, 2006, 01:24 PM
#7
Thread Starter
Lively Member
Re: How to detect the VB Form is moved and Resizing of Form is complete?
Hello!
Wow! your code works like charm! I never thought it will be possible with only two timers! It's so optimized and compact! I agree that Subclassing is the proper method for it; but considering my current project scope, I feel Timer method is perfect! Thanks a lot for your efforts and interst!
Regards,
Ruturaj.
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
|