Form flashes beneath an OpenFileDialog or 2nd Form
-
This happens more often with Debug builds than Release builds, but I often have a Form with lots of controls and, hence, lots of painting to do that launches another Form, whether it is an Open File Dialog or a new Form. Basically, the Form at the bottom of the z-order does some ugly flashing while the OpenFileDialog or new Form closes. I've tried SuspendLayout/ResumeLayout on the Form at the bottom but this doesn't seem to help with its constituent controls. Any ideas on how to stop this? I can show you screenshots if you think that would help.
-
This happens more often with Debug builds than Release builds, but I often have a Form with lots of controls and, hence, lots of painting to do that launches another Form, whether it is an Open File Dialog or a new Form. Basically, the Form at the bottom of the z-order does some ugly flashing while the OpenFileDialog or new Form closes. I've tried SuspendLayout/ResumeLayout on the Form at the bottom but this doesn't seem to help with its constituent controls. Any ideas on how to stop this? I can show you screenshots if you think that would help.
SuspendLayout
andResumeLayout
are really only useful when initializing controls. Once they're initialized, it's pointless to use them. As for the problem, do you notice the flickering when passing another window over your application (a window from another application)? If so, painting isn't the error exactly. Whatever occurs in your app in this case when you close the form is eating up enough CPU cycles - or blocking the main UI thread completely - to cause slow repainting of invalidated regions. If the behavior is the same whether you pass one of your windows, or a window from another application over yours (or minimize -> restore, whatever to invalidate your form), then you might have to consider overriding several of the more offensive controls and enable double-buffered painting. See theControl.SetStyle
method andControlStyles
enumeration documentation for details. If many of these controls are already custom controls that you've written, using a double-buffered approach to painting (if you haven't already) will help, but you should also be mindful of the invalidated region when handlingOnPaint
(its better to overrideOn_EventName_
methods when possible, as opposed to handling the events in a child class) and only repaint the invalidated regions (again, if you haven't already).-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----