Here's a good mouse detect on resize ? for everyone...

UCM

Centurion
Joined
Jan 1, 2003
Messages
135
Location
Colorado, usa
Does anyone know of a way to detect when the user finishes resizing a form so that if processor intensive code can be run at that point?

basically, I have a sub that runs it's code in about 1.5 seconds...

it scans the width and height of form1 and readjusts the controls on it accordingly for visual appearance...

the _Resize event runs every time the form has begun to resize so the code runs as long as the user has the mouse button down...

if they need to resize the window a bit but then resize it again and again, it bogs down the system and appears quite annoying to an end user...


------------
If we could detect when the user lets the left mouse button go and THen run the code, the result would be much better... the contents in the form1 will look skewed until they get done resizing the form and let the mouse button go, then it re does the control structure in the form to look pretty...
------------

Any ideas?
 
hmmm....

The thing is that I am creating multiple label controls at runtime on a panel that is dock.fill...

The thing is that it take a couple seconds to run the code for calculating the new sizes based on what the user has set the new form size to as well as the graphins used in each label control...

If I could tell it to run this code after the user lets the mouse button go after they are done resizingthe window then it would work faster that way...
 
The resize event only happens when the user has finished resizing. I cant see why yours would fire every tiny move unless your using directx ?
 
I'm still not seing why you can't use the Anchor property. I have a test form that creates a label at runtime and places it on the docked panel control. I set the Anchor property of the label and when I resize my form, I see the label resize automatically.

If you really need to trap the end of the resize, you might look into overriding or hooking the WndProc of your form and checking for Mouse_Up or NC_Mouse_Up or something like that (I'm not real proficient in the API). The NC_... is non-client and gives you messages like clicking the title bar and might give you whether the form's border is selected.... just a guess. But with .NET's new Anchor property, I'd try and take advantage of that before you invest too much time in custom resizing code.

-nerseus
 
thanx guys...

to clearify:

Grimfort:

While the user is moving their mouse, the resize event fires because it is set up to fire when the size of the control ( form1 in this case ) changes.

Also, when you first load the form or minimize/maximize then restore it, the_Resize event fires as well...

So any code you have in there is going to run a lot of times during a resizing by the user...

try this code and resize the window and you'll see what I mean:
Visual Basic:
  Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
    Me.Width = 400
    Me.Height = 200
  End Sub


Nerseus:
I miscommunicated, sorry bout that, basically, I am wrote code that takes about 500 words and numbers and puts them all in labels...the labels are the exact same width and height...

The thing is that I'm trying to get the form set up so that when the user resizes it, all of the labels will be [[[ hmmmm, Just got an idea... ]]] deleted and then redrawn according to the new size of the form...

My Idea:
As you read, yes, I said " deleted and then redrawn "...Perhaps I should just 'move' them :rolleyes: ( instead of wiping and recreating them from scratch ) when the user resizes them...

The thing is, come to think of it, that I'd have to search through all of the controls to rearrange them... In previous versions of VB, we had control indexing to make what I want to do fairly easy...

Since we don't have that anymore, I belive the best way to get this done is to use a panel that will ONLY have these labels as it's controls and then go through each control from first through last and change them accordingly...
 
Last edited:
Back
Top