Windows Develop Bookmark and Share   
 index > Windows Forms General > how can i avoid firing multi-resize event?
 

how can i avoid firing multi-resize event?

ok, maybe my title is somehow misunderstanding :)

i need re-layout multi-controls in a specified Control container, when this container resize event fired
however, when that Control container's windowstate transferred from Normal to Maxmize, for instance, multiply resize event fired, just to make my sub controls flicker, which is i can not accept.

any other approach to avoid flicker when re-layout sub controls ina specified container Control?

ps. i had tried toinvoke SendMessage(WM_SETREDRAW, 0, 0) before re-layout and SendMessage(WM_SETREDRAW, 1, 0) after re-layout, it won't make sense :(
micyng  Monday, September 07, 2009 12:26 PM
Thanks Aland Li

i had one question, base on your words: the WM_SETREDRAW message can be used to allow or prevent the window being redrawn. So I suggest that we should not send this message to a control

WHY? as far as i know, the Control class has encapsulated BeginUpdateInternal and EndUpdateInternal method in itself, and these two methods had invoked SendMessage(WM_SETREDRAW, 0, 0) directly, your solution won't make sense :)

and i finally had one alternative approach, i can invoke WM_SETREDRAW just at entry before specified control state transferring, and invoke another WM_SETREDRAW when the target state transferred, at once. Though stillmultiply resize event triggered, the control itself won't redraw at all, no any flicker occured

whatever, your suggestion about unbind resize event and re-bind give me lots of help, and the LockWindowUpdate api function, thanks so much
micyng  Wednesday, September 09, 2009 1:17 PM
If I understand you correctly, I believe what you need is to use Control.SuspendLayout before your resize, and Control.ResumeLayout at the end.

This is the way forms handle their initial layout, for exactly this type of scenario.
Reed Copsey, Jr. - http://reedcopsey.com
Reed Copsey, Jr.  Monday, September 07, 2009 9:14 PM
thanks Reed

i had tried your suggestion, however it won't work, either :(
and i need take some of my topics back, i had tried SendMessage(WM_SETREDRAW, 0, 0) on that container itself, and it works, i mean, those subcontrols won't flicker at all, when the container control state transferred from Normal to Maxmized

However, when the container control's state transferred from Maxmized to Normal, strange things happened, the taskbar KEEPs un-redrawed, in another word, i just saw a broken taskbar
micyng  Tuesday, September 08, 2009 3:45 AM
Hi micyng,

Based on my understanding, what you did in the Resize event handler to re-layout would fire the event itself. We can remove the handler at the start of the handler and add it again at the end. This is a code snippet:
private void panel1_Resize(object sender, EventArgs e)
{
    //Remove the handler to prevent the event being fired multiply
    this.panel1.Resize -= new EventHandler(panel1_Resize);
    //Re-layout some controls here.
    //Set the handler back.
    this.panel1.Resize += new EventHandler(panel1_Resize);
}
As far as I know, the WM_SETREDRAW message can be used to allow or prevent the window being redrawn. So I suggest that we should not send this message to a control. In another aspect, if the Resize event would be fired multiply, the message would also be sent multiply, this would also result in some error.
These are some documents about the WM_SETREDRAW message:
http://msdn.microsoft.com/en-us/library/dd145219(VS.85).aspx.
http://blogs.msdn.com/oldnewthing/archive/2007/02/22/1742084.aspx.

Let me know if this does not help.
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Wednesday, September 09, 2009 3:29 AM
Thanks Aland Li

i had one question, base on your words: the WM_SETREDRAW message can be used to allow or prevent the window being redrawn. So I suggest that we should not send this message to a control

WHY? as far as i know, the Control class has encapsulated BeginUpdateInternal and EndUpdateInternal method in itself, and these two methods had invoked SendMessage(WM_SETREDRAW, 0, 0) directly, your solution won't make sense :)

and i finally had one alternative approach, i can invoke WM_SETREDRAW just at entry before specified control state transferring, and invoke another WM_SETREDRAW when the target state transferred, at once. Though stillmultiply resize event triggered, the control itself won't redraw at all, no any flicker occured

whatever, your suggestion about unbind resize event and re-bind give me lots of help, and the LockWindowUpdate api function, thanks so much
micyng  Wednesday, September 09, 2009 1:17 PM
Hi micyng,

So your issue is already solved via sending WM_SETREDRAW message? If so, I would mark your reply as answer.

Regards,
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Thursday, September 10, 2009 2:14 AM
yes, it's solved :)
micyng  Thursday, September 10, 2009 12:26 PM

You can use google to search for other answers

Custom Search

More Threads

• using default Windows login form in windows applications
• Problems with SoundPlayer
• Display a form's icon in a button control
• Align autosize labels on the right
• WebBrowser control and file downloads
• ListBox Problem
• multiline textbox problem
• select query using command text
• How can execute a custom file with C#?
• Getting parameter info from a Delegate type