469,631 Members | 979 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,631 developers. It's quick & easy.

Resizing a form

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 form1, but it
dosn't get called when resizing :(

I would like to be able to resize my form, but also make sure the graph is
only redrawn when the user is not resizing any more.

Hope my question make sense :)

--
Søren Reinke
www.Xray-Mag.com/ - Your free diving magazin on the net.
Current issue Diving in North America, 99 pages.
Download it in PDF
Nov 17 '05 #1
12 6463
Søren Reinke wrote:
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 form1, but it
dosn't get called when resizing :(

I would like to be able to resize my form, but also make sure the graph is
only redrawn when the user is not resizing any more.

Hope my question make sense :)


First, override OnResize() and the first time you enter that method,
you set a flag. You also call this.SuspendLayout();, if the flag was
wasn't set already.

then, you override OnSizeChanged. In there, you reset the flag and call
this.ResumeLayout(false);. Then draw your graph.

Frans

--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Nov 17 '05 #2
"Søren Reinke" <so***@reinke.fjernmig.dk> wrote in message
news:d5***********@newsbin.cybercity.dk...
How do i make sure that a graph is not redrawn while the form with the
graph is being resized ?

I would like to be able to resize my form, but also make sure the graph is
only redrawn when the user is not resizing any more.


It depends on the control. Sometimes there is a BeginUpdate/EndUpdate
mechanism, other times you have to call the Win32 ValidateRect() function,
passing in the control's window handle and client area.

-- Alan
Nov 17 '05 #3
>>
I would like to be able to resize my form, but also make sure the graph
is only redrawn when the user is not resizing any more.

Hope my question make sense :)


First, override OnResize() and the first time you enter that method, you
set a flag. You also call this.SuspendLayout();, if the flag was wasn't
set already.

then, you override OnSizeChanged. In there, you reset the flag and call
this.ResumeLayout(false);. Then draw your graph.

Frans

Hi Frans

Thanks for the tip, i'll try it :)

--
Søren Reinke
www.Xray-Mag.com/ - Your free diving magazin on the net.
Current issue Diving in North America, 99 pages.
Download it in PDF
Nov 17 '05 #4
I have a similar problem, but I don't see how this will work. Both Resize
and SizeChanged events get called multiple times during a single resizing
drag.

-Rachel

"Frans Bouma [C# MVP]" <pe******************@xs4all.nl> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Søren Reinke wrote:
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 form1, but it
dosn't get called when resizing :(

I would like to be able to resize my form, but also make sure the graph is only redrawn when the user is not resizing any more.

Hope my question make sense :)


First, override OnResize() and the first time you enter that method,
you set a flag. You also call this.SuspendLayout();, if the flag was
wasn't set already.

then, you override OnSizeChanged. In there, you reset the flag and call
this.ResumeLayout(false);. Then draw your graph.

Frans

--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------

Nov 17 '05 #5
Rachel Suddeth wrote:
I have a similar problem, but I don't see how this will work. Both Resize
and SizeChanged events get called multiple times during a single resizing
drag.
Hmm. If SizeChanged is called multiple times, it indeed has a problem.
It then gets hacky, you then have to set a timer or something :X...

FB

-Rachel

"Frans Bouma [C# MVP]" <pe******************@xs4all.nl> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Søren Reinke wrote:
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 form1, but it
dosn't get called when resizing :(

I would like to be able to resize my form, but also make sure the graph
is
only redrawn when the user is not resizing any more.

Hope my question make sense :)


First, override OnResize() and the first time you enter that method,
you set a flag. You also call this.SuspendLayout();, if the flag was
wasn't set already.

then, you override OnSizeChanged. In there, you reset the flag and call
this.ResumeLayout(false);. Then draw your graph.

--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Nov 17 '05 #6
The following link gives a VB solution, but it should be simple enough to
convert to C#

http://groups.google.co.uk/group/mic...a09c0cf8b9d9ca

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Frans Bouma [C# MVP]" <pe******************@xs4all.nl> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Rachel Suddeth wrote:
I have a similar problem, but I don't see how this will work. Both Resize
and SizeChanged events get called multiple times during a single resizing
drag.


Hmm. If SizeChanged is called multiple times, it indeed has a problem. It
then gets hacky, you then have to set a timer or something :X...

FB

-Rachel

"Frans Bouma [C# MVP]" <pe******************@xs4all.nl> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Søren Reinke wrote:

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 form1, but it
dosn't get called when resizing :(

I would like to be able to resize my form, but also make sure the graph


is
only redrawn when the user is not resizing any more.

Hope my question make sense :)

First, override OnResize() and the first time you enter that method,
you set a flag. You also call this.SuspendLayout();, if the flag was
wasn't set already.

then, you override OnSizeChanged. In there, you reset the flag and call
this.ResumeLayout(false);. Then draw your graph.

--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------

Nov 17 '05 #7
Thanks, Mick, looks like that should work.
BTW, where do you get the constants from (for Windows messages)? You pull
them from a C++ header file?

-Rachel

"Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote in
message news:eg**************@TK2MSFTNGP14.phx.gbl...
The following link gives a VB solution, but it should be simple enough to
convert to C#

http://groups.google.co.uk/group/mic...a09c0cf8b9d9ca
--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Frans Bouma [C# MVP]" <pe******************@xs4all.nl> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Rachel Suddeth wrote:
I have a similar problem, but I don't see how this will work. Both Resize and SizeChanged events get called multiple times during a single resizing drag.


Hmm. If SizeChanged is called multiple times, it indeed has a problem. It then gets hacky, you then have to set a timer or something :X...

FB

-Rachel

"Frans Bouma [C# MVP]" <pe******************@xs4all.nl> wrote in message news:%2****************@TK2MSFTNGP12.phx.gbl...

Søren Reinke wrote:

>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 form1, but it
>dosn't get called when resizing :(
>
>I would like to be able to resize my form, but also make sure the graph
is

>only redrawn when the user is not resizing any more.
>
>Hope my question make sense :)

First, override OnResize() and the first time you enter that method,
you set a flag. You also call this.SuspendLayout();, if the flag was
wasn't set already.

then, you override OnSizeChanged. In there, you reset the flag and call
this.ResumeLayout(false);. Then draw your graph.

--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------


Nov 17 '05 #8
Depends on my mood. Sometimes I look them up (winuser.h in this case),
sometimes I google and sometimes I just put Console.WriteLine(m.ToString());
in the WndProc() method. Usually the latter since I'm often checking to see
what messages are being sent. Then it's off to the MSDN documentation to
find out what info I can read/change for the message.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Rachel Suddeth" <ra****@bldhound.com> wrote in message
news:OS**************@TK2MSFTNGP15.phx.gbl...
Thanks, Mick, looks like that should work.
BTW, where do you get the constants from (for Windows messages)? You pull
them from a C++ header file?

-Rachel

"Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote
in
message news:eg**************@TK2MSFTNGP14.phx.gbl...
The following link gives a VB solution, but it should be simple enough to
convert to C#

http://groups.google.co.uk/group/mic...a09c0cf8b9d9ca

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Frans Bouma [C# MVP]" <pe******************@xs4all.nl> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
> Rachel Suddeth wrote:
>> I have a similar problem, but I don't see how this will work. Both Resize >> and SizeChanged events get called multiple times during a single resizing >> drag.
>
> Hmm. If SizeChanged is called multiple times, it indeed has a problem. It > then gets hacky, you then have to set a timer or something :X...
>
> FB
>
>>
>> -Rachel
>>
>> "Frans Bouma [C# MVP]" <pe******************@xs4all.nl> wrote in message >> news:%2****************@TK2MSFTNGP12.phx.gbl...
>>
>>>Søren Reinke wrote:
>>>
>>>>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 form1, but
>>>>it
>>>>dosn't get called when resizing :(
>>>>
>>>>I would like to be able to resize my form, but also make sure the graph >>
>> is
>>
>>>>only redrawn when the user is not resizing any more.
>>>>
>>>>Hope my question make sense :)
>>>
>>>First, override OnResize() and the first time you enter that method,
>>>you set a flag. You also call this.SuspendLayout();, if the flag was
>>>wasn't set already.
>>>
>>>then, you override OnSizeChanged. In there, you reset the flag and
>>>call
>>>this.ResumeLayout(false);. Then draw your graph.
>
>
> --
> ------------------------------------------------------------------------
> Get LLBLGen Pro, productive O/R mapping for .NET:
> http://www.llblgen.com
> My .NET blog: http://weblogs.asp.net/fbouma
> Microsoft MVP (C#)
> ------------------------------------------------------------------------



Nov 17 '05 #9
All right, I don't know VB, and I've never needed to do masking with C#, so
I have a couple questions about how to translate the WndProc in your
example. I think the "Static Sizemode" inside the method would have to be
replaces by a class level variable in C#? Also not quite sure about the
statement to set SizeMode?

----
private bool bSizeMode = false;
protected override void WndProc(ref Message m)
{
switch ( m.Msg )
{
case WM_SIZING:
// Resize event already provided
break;
case WM_SYSCOMMAND:
bSizeMode = ((m.WParam.ToInt32() & 0xFFF0) == SC_SIZE);
break;
case WM_ENTERSIZEMOVE:
if ( bSizeMode )
{
OnBeginResize(EventArgs.Empty);
}
break;
case WM_EXITSIZEMOVE:
{
if ( bSizeMode )
{
OnEndResize(EventArgs.Empty);
}
break;
}

} // end switch
base.WndProc (ref m);
}
----

Here is the VB code "copied" above
------
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Static SizeMode As Boolean = False
Select Case m.Msg
Case WM_SIZING
'Already have a Resize Method
Case WM_SYSCOMMAND
SizeMode = ((m.WParam.ToInt32 And &HFFF0) = SC_SIZE)
Case WM_ENTERSIZEMOVE
If SizeMode Then
OnBeginResize(EventArgs.Empty)
End If
Case WM_EXITSIZEMOVE
If SizeMode Then
OnEndResize(EventArgs.Empty)
End If
Case Else
End Select
MyBase.WndProc(m)
End Sub

---
Thanks,

Rachel

"Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote in
message news:eg**************@TK2MSFTNGP14.phx.gbl...
The following link gives a VB solution, but it should be simple enough to
convert to C#

http://groups.google.co.uk/group/mic...a09c0cf8b9d9ca
--
Mick Doherty
http://dotnetrix.co.uk/nothing.html

Nov 17 '05 #10
Nevermind, it's working perfectly so it must be right :-)
Here is the whole business in C#, in case that helps anyone...

---
// Variables having to do with the resizing code follow
protected bool bSizeMode = false;

/// <summary>
/// Windows Constants for WndProc call in BeginResize/EndResize events
/// </summary>
protected const int WM_SIZING = 0x214,
WM_ENTERSIZEMOVE = 0x231,
WM_EXITSIZEMOVE = 0x232,
WM_SYSCOMMAND = 0x112,
SC_SIZE = 0xF000;

/// <summary>
/// Fires once at the beginning of a resizing drag.
/// </summary>
public event EventHandler BeginResize;

/// <summary>
/// Fires once at the end of a resizing drag.
/// </summary>
public event EventHandler EndResize;
/// <summary>
/// Process Windows messages (in this case to provide Begin/EndResize events
/// </summary>
/// <param name="m"></param>
protected override void WndProc(ref Message m)
{
switch ( m.Msg )
{
case WM_SIZING:
// Resize event already provided
break;
case WM_SYSCOMMAND:
bSizeMode = ((m.WParam.ToInt32() & 0xFFF0) == SC_SIZE);
break;
case WM_ENTERSIZEMOVE:
if ( bSizeMode )
{
OnBeginResize(EventArgs.Empty);
}
break;
case WM_EXITSIZEMOVE:
{
if ( bSizeMode )
{
OnEndResize(EventArgs.Empty);
}
break;
}

} // end switch
base.WndProc (ref m);
}
/// <summary>
/// Raise BeginResize event
/// </summary>
/// <param name="e"></param>
protected virtual void OnBeginResize(System.EventArgs e)
{
if ( BeginResize != null )
BeginResize(this, e);
}

/// <summary>
/// Raise EndResize event
/// </summary>
/// <param name="e"></param>
protected virtual void OnEndResize(System.EventArgs e)
{
if ( EndResize != null )
EndResize(this, e);
}
---
Nov 17 '05 #11
You're right that VB's local Static variable must be declared as a Class
level variable in C#.

....and the translation looks good to me :-)

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Rachel Suddeth" <ra****@bldhound.com> wrote in message
news:ed*************@TK2MSFTNGP12.phx.gbl...
Nevermind, it's working perfectly so it must be right :-)
Here is the whole business in C#, in case that helps anyone...

---
// Variables having to do with the resizing code follow
protected bool bSizeMode = false;

/// <summary>
/// Windows Constants for WndProc call in BeginResize/EndResize events
/// </summary>
protected const int WM_SIZING = 0x214,
WM_ENTERSIZEMOVE = 0x231,
WM_EXITSIZEMOVE = 0x232,
WM_SYSCOMMAND = 0x112,
SC_SIZE = 0xF000;

/// <summary>
/// Fires once at the beginning of a resizing drag.
/// </summary>
public event EventHandler BeginResize;

/// <summary>
/// Fires once at the end of a resizing drag.
/// </summary>
public event EventHandler EndResize;
/// <summary>
/// Process Windows messages (in this case to provide Begin/EndResize
events
/// </summary>
/// <param name="m"></param>
protected override void WndProc(ref Message m)
{
switch ( m.Msg )
{
case WM_SIZING:
// Resize event already provided
break;
case WM_SYSCOMMAND:
bSizeMode = ((m.WParam.ToInt32() & 0xFFF0) == SC_SIZE);
break;
case WM_ENTERSIZEMOVE:
if ( bSizeMode )
{
OnBeginResize(EventArgs.Empty);
}
break;
case WM_EXITSIZEMOVE:
{
if ( bSizeMode )
{
OnEndResize(EventArgs.Empty);
}
break;
}

} // end switch
base.WndProc (ref m);
}
/// <summary>
/// Raise BeginResize event
/// </summary>
/// <param name="e"></param>
protected virtual void OnBeginResize(System.EventArgs e)
{
if ( BeginResize != null )
BeginResize(this, e);
}

/// <summary>
/// Raise EndResize event
/// </summary>
/// <param name="e"></param>
protected virtual void OnEndResize(System.EventArgs e)
{
if ( EndResize != null )
EndResize(this, e);
}
---

Nov 17 '05 #12
> Here is the whole business in C#, in case that helps anyone...

---


Thanks Rachel

I'll try to implement it soon.

--
Søren Reinke
www.Xray-Mag.com/ - Your free diving magazin on the net.
Current issue Diving in North America, 99 pages.
Download it in PDF
Nov 17 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Jozef | last post: by
4 posts views Thread by Thomas Richter | last post: by
6 posts views Thread by John Bowman | last post: by
11 posts views Thread by Sharon | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.