When connected to RDC , Iam observing flickering issues for the background images of mdi child forms. How can I avoid them?
I am using this code, no flicker at all.
if (!CheckForm(childForm))
{
childForm.WindowState = FormWindowState.Minimized; //avoid flickering
childForm.Show();
childForm.WindowState = FormWindowState.Normal;
}
else
{
childForm.BringToFront();
childForm.WindowState = FormWindowState.Minimized;
childForm.Activate();
childForm.WindowState = FormWindowState.Normal;
}
I know this is a very late answer, but since all answers here (including the accepted) did not do anything against the flickering, I still like to post what did it for me
first of all, I had to do this
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
// reduce flickering when switching mdi child forms (see also WndProc)
cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED (which is essentially double buffered)
return cp;
}
}
But this is not enough, I also had to do this :
protected override void WndProc(ref Message msg)
{
const int WM_NCPAINT = 0x85;
const int WM_SIZE = 0x05;
// reduce flickering when switching mdi child forms (see also CreateParams)
if (msg.Msg == WM_NCPAINT)
{
if (this.WindowState == FormWindowState.Maximized)
return;
}
// reduce flickering when switching mdi child forms (see also CreateParams)
if (msg.Msg == WM_SIZE)
{
if (this.WindowState == FormWindowState.Maximized)
return;
}
base.WndProc(ref msg);
}
I had read somewhere that I could achive all this by simply doing this :
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
But the flickering only gets worse when I do that.
Anyway, with this solution (at least in my mdi project) I have completely eliminated the flickering when switching between mdi child forms.
Hope this can help anyone looking for this problem.
Have you tried the following?
this.DoubleBuffered = true;
Put this in the constructor after the InitializeComponent.
I have been also struggling with same problem and didn't find anything what works including form.DoubleBuffered = true. So this is what works for me
form.WindowState = FormWindowState.Minimized;
form.Show();
form.WindowState = FormWindowState.Maximized;
On the designer side, leave the form window state to Normal.
I also faced this issue for a long time. And I just got this way to come out. Opening forms in Fill Dock mode instead of Maximized.
//childFrm.WindowState = FormWindowState.Maximized;
childFrm.Dock = DockStyle.Fill;
Remove any background image in MDI form.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.