C# Remove flickering in MDI applications.

If you have ever been working with MDI applications, and while to MDI windows are while the MDI windows are maximized and you switch you see a flicker of the windows.

Well below is a simple quick fix for solving this issue.

So firstly lets define some constants that we will be using.

const int WM_NCPAINT = 0x85;
const int WM_SIZE = 0x05;

Now override the WndProc method in the MDI child window(s).

protected override void WndProc(ref Message m)
    if (m.Msg == WM_NCPAINT) 
        if(this.WindowState == FormWindowState.Maximized)

    if (m.Msg == WM_SIZE)
        if (this.WindowState == FormWindowState.Maximized)

     base.WndProc(ref m);

and viola your flickering issues are gone.


6 thoughts on “C# Remove flickering in MDI applications.

  1. Rejoiced too soon…
    To avoid not repainting inactive mdichilds after resizing mdiparent
    with active child on resizable bigger mdi parent forms, load childs with
    frmxyz.Dock = DockStyle.Fill;
    instead of
    frmxyz..WindowState = FormWindowState.Maximized;
    and replace alle
    this.ActiveMdiChild.WindowState = FormWindowState.Maximized;
    this.ActiveMdiChild.Dock = DockStyle.Fill;

    On small, not resizable mdiclients with size-adjusted parents WindowState = FormWindowState.Maximized; is OK.

    Removed your code.

    Thanks anyway

  2. I came to your “C” page and noticed you could have a lot more traffic. I have found that the key to running a website is making sure the visitors you are getting are interested in your subject matter. There is a company that you can get traffic from and they let you try it for free. I managed to get over 300 targetted visitors to day to my website. Visit them today: http://voxseo.com/traffic/

  3. It’s worth mentioning that this method prevents drawing MDI control buttons for child form (minimize, maximize and close buttons). After creating another form, controls are redrawn. Fixing that would be great.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s