472,975 Members | 1,491 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,975 software developers and data experts.

Question about handling form resizing events.

I have a WinForms based application written for the .NET Framework 2.0
and in this application I need to be able to be able to take some
action in code when the user finishes resizing the form.

I can easily create an event handler for the SizeChanged form level
event, the problem is if the user is using a mouse drag to resize the
form this event is firing every few milliseconds or what have you
until the user stops the drag process.

The approach I've taken is to create a Timer object and inside that
timer Tick event handler check the status of a flag that I'm setting
inside the form SizeChanged event handler. As I suspected, this a
sloppy approach that feels like a hack and it doesn't work without
bugs.

Can anyone recommend a proper way to do this?

Jun 22 '07 #1
6 4460
Check Form.ResizeEnd event

HTH
Alex
"JDeats" <Je**********@gmail.comwrote in message
news:11**********************@u2g2000hsc.googlegro ups.com...
>I have a WinForms based application written for the .NET Framework 2.0
and in this application I need to be able to be able to take some
action in code when the user finishes resizing the form.

I can easily create an event handler for the SizeChanged form level
event, the problem is if the user is using a mouse drag to resize the
form this event is firing every few milliseconds or what have you
until the user stops the drag process.

The approach I've taken is to create a Timer object and inside that
timer Tick event handler check the status of a flag that I'm setting
inside the form SizeChanged event handler. As I suspected, this a
sloppy approach that feels like a hack and it doesn't work without
bugs.

Can anyone recommend a proper way to do this?


Jun 22 '07 #2
JDeats,

I would extend the Form class and override the WndProc method. In it,
when you come across the WM_SIZE notification (it's value is 5, btw) you can
fire an event to indicate that the resizing operation has been completed.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"JDeats" <Je**********@gmail.comwrote in message
news:11**********************@u2g2000hsc.googlegro ups.com...
>I have a WinForms based application written for the .NET Framework 2.0
and in this application I need to be able to be able to take some
action in code when the user finishes resizing the form.

I can easily create an event handler for the SizeChanged form level
event, the problem is if the user is using a mouse drag to resize the
form this event is firing every few milliseconds or what have you
until the user stops the drag process.

The approach I've taken is to create a Timer object and inside that
timer Tick event handler check the status of a flag that I'm setting
inside the form SizeChanged event handler. As I suspected, this a
sloppy approach that feels like a hack and it doesn't work without
bugs.

Can anyone recommend a proper way to do this?

Jun 22 '07 #3
That works too!

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"AlexS" <sa***********@SPAMrogers.comPLEASEwrote in message
news:%2******************@TK2MSFTNGP03.phx.gbl...
Check Form.ResizeEnd event

HTH
Alex
"JDeats" <Je**********@gmail.comwrote in message
news:11**********************@u2g2000hsc.googlegro ups.com...
>>I have a WinForms based application written for the .NET Framework 2.0
and in this application I need to be able to be able to take some
action in code when the user finishes resizing the form.

I can easily create an event handler for the SizeChanged form level
event, the problem is if the user is using a mouse drag to resize the
form this event is firing every few milliseconds or what have you
until the user stops the drag process.

The approach I've taken is to create a Timer object and inside that
timer Tick event handler check the status of a flag that I'm setting
inside the form SizeChanged event handler. As I suspected, this a
sloppy approach that feels like a hack and it doesn't work without
bugs.

Can anyone recommend a proper way to do this?



Jun 22 '07 #4
On Jun 22, 3:29 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
JDeats,

I would extend the Form class and override the WndProc method. In it,
when you come across the WM_SIZE notification (it's value is 5, btw) you can
fire an event to indicate that the resizing operation has been completed.

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

"JDeats" <Jeremy.De...@gmail.comwrote in message

news:11**********************@u2g2000hsc.googlegro ups.com...
I have a WinForms based application written for the .NET Framework 2.0
and in this application I need to be able to be able to take some
action in code when the user finishes resizing the form.
I can easily create an event handler for the SizeChanged form level
event, the problem is if the user is using a mouse drag to resize the
form this event is firing every few milliseconds or what have you
until the user stops the drag process.
The approach I've taken is to create a Timer object and inside that
timer Tick event handler check the status of a flag that I'm setting
inside the form SizeChanged event handler. As I suspected, this a
sloppy approach that feels like a hack and it doesn't work without
bugs.
Can anyone recommend a proper way to do this?
Thanks that put me on the right track.... Since I needed to not only
detect when resizing ended but also when the maximize restore buttons
are pressed I had to resort to overriding WndProc anyway.

For anyone else looking to call a method whenever the user resizes the
form by mouse drag or by way of maximize restore buttons here, this
does work. Spent bout five hours on this issue.... There are days I
absolutely hate the .NET Framework team for not putting in enough
event handlers. It's seems like there might be many instances where
someone would want an event to trap on when the Form size is changed
or when the form has been maximized/restored.

Here's the code.
private bool inSizing = false;

private void OnFormResizeEnd()
{
// code to execute after sizing is done goes here.
}

protected override void WndProc(ref
System.Windows.Forms.Message m)
{

const int WM_SYSCOMMAND = 0x0112;
const int SC_MAXIMIZE = 0xF030;
const int SC_RESTORE = 0xF120;
const int WM_SIZING = 0x214;
const int WM_EXITSIZEMOVE = 0x232;

if (m.Msg == WM_SIZING)
{
inSizing = true;
}

if (m.Msg == WM_EXITSIZEMOVE && inSizing) //
WM_EXITSIZEMOVE
{
OnFormResizeEnd();
inSizing = false;
}

if (m.Msg == WM_SYSCOMMAND)
{
if ( (int)m.WParam == SC_MAXIMIZE)
{
OnFormResizeEnd();
inSizing = false;
}
}

if (m.Msg == WM_SYSCOMMAND)
{
if ( (int)m.WParam == SC_RESTORE)
{
OnFormResizeEnd();
inSizing = false;
}
}

base.WndProc(ref m);

}

Jun 22 '07 #5
On Fri, 22 Jun 2007 14:20:33 -0700, JDeats <Je**********@gmail.comwrote:
[...]
For anyone else looking to call a method whenever the user resizes the
form by mouse drag or by way of maximize restore buttons here, this
does work.
Thanks for posting the code for reference to others. One suggestion
though: IMHO, it would be better to use a switch() than to use several
independent if() statements. At the very least, use "else if()" for the
subsequent if() statements. :)
Jun 23 '07 #6
Or you can use the Form's SizeChanged event.

"JDeats" <Je**********@gmail.comwrote in message
news:11*********************@e9g2000prf.googlegrou ps.com...
On Jun 22, 3:29 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
>JDeats,

I would extend the Form class and override the WndProc method. In
it,
when you come across the WM_SIZE notification (it's value is 5, btw) you
can
fire an event to indicate that the resizing operation has been completed.

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

"JDeats" <Jeremy.De...@gmail.comwrote in message

news:11**********************@u2g2000hsc.googlegr oups.com...
>I have a WinForms based application written for the .NET Framework 2.0
and in this application I need to be able to be able to take some
action in code when the user finishes resizing the form.
I can easily create an event handler for the SizeChanged form level
event, the problem is if the user is using a mouse drag to resize the
form this event is firing every few milliseconds or what have you
until the user stops the drag process.
The approach I've taken is to create a Timer object and inside that
timer Tick event handler check the status of a flag that I'm setting
inside the form SizeChanged event handler. As I suspected, this a
sloppy approach that feels like a hack and it doesn't work without
bugs.
Can anyone recommend a proper way to do this?

Thanks that put me on the right track.... Since I needed to not only
detect when resizing ended but also when the maximize restore buttons
are pressed I had to resort to overriding WndProc anyway.

For anyone else looking to call a method whenever the user resizes the
form by mouse drag or by way of maximize restore buttons here, this
does work. Spent bout five hours on this issue.... There are days I
absolutely hate the .NET Framework team for not putting in enough
event handlers. It's seems like there might be many instances where
someone would want an event to trap on when the Form size is changed
or when the form has been maximized/restored.

Here's the code.
private bool inSizing = false;

private void OnFormResizeEnd()
{
// code to execute after sizing is done goes here.
}

protected override void WndProc(ref
System.Windows.Forms.Message m)
{

const int WM_SYSCOMMAND = 0x0112;
const int SC_MAXIMIZE = 0xF030;
const int SC_RESTORE = 0xF120;
const int WM_SIZING = 0x214;
const int WM_EXITSIZEMOVE = 0x232;

if (m.Msg == WM_SIZING)
{
inSizing = true;
}

if (m.Msg == WM_EXITSIZEMOVE && inSizing) //
WM_EXITSIZEMOVE
{
OnFormResizeEnd();
inSizing = false;
}

if (m.Msg == WM_SYSCOMMAND)
{
if ( (int)m.WParam == SC_MAXIMIZE)
{
OnFormResizeEnd();
inSizing = false;
}
}

if (m.Msg == WM_SYSCOMMAND)
{
if ( (int)m.WParam == SC_RESTORE)
{
OnFormResizeEnd();
inSizing = false;
}
}

base.WndProc(ref m);

}

Jun 23 '07 #7

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

Similar topics

2
by: Marinos Christoforou | last post by:
Sorry if this has been asked before but as an inexperienced wanna-be C# programmer I wondering how to code classes to help build a standard Windows UI. For example to build a common toolbar. I...
2
by: Eric Newton | last post by:
VB's more declarative nature of handling events is golden. I'm hoping C# will acquire this type of deal, in addition to the anonymous delegates. could do same as vb (actually would be easier to...
5
by: ECVerify.com | last post by:
This should be a basic question. In VB.NET in the two drop downs over the source code for a form you can get a list of the events and overrides for that form. In VC++ in the properties window...
1
by: Natalia DeBow | last post by:
Hi, I am working on a Windows-based client-server application. I am involved in the development of the remote client modules. I am using asynchronous delegates to obtain information from...
12
by: Søren Reinke | last post by:
Hi there I have a little problem. How do i make sure that a graph is not redrawn while the form with the graph is being resized ? I have tried to add a mouse up/down event handler on the...
12
by: scsharma | last post by:
Hi, I am working on creating a webapplication and my design calls for creating main webform which will have menu bar on left hand side and a IFrame which will contain all the forms that are shown...
11
by: Ajith Menon | last post by:
I have created a windows application in which the form needs to be resized on the MouseMove event. The windows resize function takes a lot of CPU cycles. And as the resize function is called on the...
9
by: dli07 | last post by:
Hello, I'm trying to convert a piece of code that creates a dynamic vertical resizing bar in a table from internet explorer to firefox. It's based on a post from...
0
by: Peter Anthony | last post by:
It seems kind of strange that if a Form is just moved that Resize events fire. This makes it hard to tell the difference betweeen resizing and moving a Form. I can understand why resizing might...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.