How to suspend drawing operation of a form ?
-
How to suspend drawing operation of a form while a block of operations is done ? For example I need to draw some things on the form and to move some controls so that the form doesn't repaint after each of them was moved.
I'll give this a shot but a .NET guru might be able to point out a fatal flaw in my case, but here goes. I know for sure that we could do something like this with streight WinAPI stuff but how will .NET controls handle it. Who knows. Anyway the theory works like this. The message pump for your application is dispatching messages to all of your windows and controls. Just disable the pump, do your thing with the controls (in a non-gui thread) but be carefull not to use any blocking calls that rely on a message back (the pump is off now remember), then when you are all done, turn the pump back on and issue a WM_PAINT. I've done similar things in C++ using the WinAPI without hitches (usually). Also note that the manipilation of the controls is being done in a NON-GUI thread but I think that as long as you are carefull about what you are doing to those controls, you should be alright. Be quick though because I believe windows sends some kind of a heartbeat message every so often and if it detects that your pump is down, it'll pop up a dialog saying your app has stopped responding. Not sure the mechanism winsdows is using for this but i suspect it's using a WM_NCPAINT to detect this somehow. Not sure how to turn the pump (message dispatcher) off in .NET application but I assume it's probably pretty easy. *** NOTE I assume that the controls you try to move about the form are issuing an Invalidate which causes the main form and the control to receive a WM_PAINT... Make sure you are not issuing and Invalidate or a refresh anywhere in your code that moves these around until you are all done. Probably not too much help but it'll give you a starting point. .NET GUI gurus, any ideas? Will this blow up in his face in .NET?
-
I'll give this a shot but a .NET guru might be able to point out a fatal flaw in my case, but here goes. I know for sure that we could do something like this with streight WinAPI stuff but how will .NET controls handle it. Who knows. Anyway the theory works like this. The message pump for your application is dispatching messages to all of your windows and controls. Just disable the pump, do your thing with the controls (in a non-gui thread) but be carefull not to use any blocking calls that rely on a message back (the pump is off now remember), then when you are all done, turn the pump back on and issue a WM_PAINT. I've done similar things in C++ using the WinAPI without hitches (usually). Also note that the manipilation of the controls is being done in a NON-GUI thread but I think that as long as you are carefull about what you are doing to those controls, you should be alright. Be quick though because I believe windows sends some kind of a heartbeat message every so often and if it detects that your pump is down, it'll pop up a dialog saying your app has stopped responding. Not sure the mechanism winsdows is using for this but i suspect it's using a WM_NCPAINT to detect this somehow. Not sure how to turn the pump (message dispatcher) off in .NET application but I assume it's probably pretty easy. *** NOTE I assume that the controls you try to move about the form are issuing an Invalidate which causes the main form and the control to receive a WM_PAINT... Make sure you are not issuing and Invalidate or a refresh anywhere in your code that moves these around until you are all done. Probably not too much help but it'll give you a starting point. .NET GUI gurus, any ideas? Will this blow up in his face in .NET?
Yes, I have done it like this. Maybe there is a certain function in .NET that makes the same , but in an easier way. Something like: BeginUpdate(); .... some code here ... EndUpdate(); Between these 2 tags the controls are not repainted. Now I have made it through message filtering, i.e. I have a variable , which when set TRUE, paint messages are not allowed to be dispatched to controls contained in the form. Works well.
-
How to suspend drawing operation of a form while a block of operations is done ? For example I need to draw some things on the form and to move some controls so that the form doesn't repaint after each of them was moved.
SuspendLayout();
... do your control moving, etc
ResumeLayout();
-- Help me! I'm turning into a grapefruit! Buzzwords!
-
SuspendLayout();
... do your control moving, etc
ResumeLayout();
-- Help me! I'm turning into a grapefruit! Buzzwords!
-
SuspendLayout is a bullshit. It doesn't work as it should. It do blocks some of the controls repainting, but allows others. I have tried it many times - and it never worked as expected.
Heh, fair enough.. it's worked exactly as I wanted in the places I've used it, anyway Are you using custom controls? Perhaps those aren't too well designed for C# usage, or something :~ -- Help me! I'm turning into a grapefruit! Buzzwords!
-
Heh, fair enough.. it's worked exactly as I wanted in the places I've used it, anyway Are you using custom controls? Perhaps those aren't too well designed for C# usage, or something :~ -- Help me! I'm turning into a grapefruit! Buzzwords!
Actually I use standart controls in a usercontrol. And this usercontrol is placed on a form. Anyway - I read somewhere that SuspendLayout works only a few of the controls, because many of them has their own way of painting. With standart controls, probably like buttons, labels - it may work. With textboxes it doesn't work for sure (as it's controled by Windows).