1

I have a "Master" form with navigation buttons on the left side, and a panel on the right that I use as a holder for child forms. It's pretty simple but the code for this is below.

public void showForm(Form form)
{
    // Disposed Prior Form & Load New
    form.Dock = DockStyle.Fill;
    form.TopLevel = false;
    pnlMain.Controls.Clear();
    pnlMain.Controls.Add(form);
    form.Show();
}

The Main issue I'm having is that everything works fine, I get virtually no flicker using the code below when navigating from form to form, but as soon as I maximize my "Master" form (which in turn enlarges the "Child" form)... even if I un-maximize and go back to the original size it starts flickering like crazy when I navigate to a new form. It's as if after maximizing it completely disregards the code put in place to fix the flickering in the first place. I should also mention that the "Child" Form has it's own form draw event which is why I have these things in place to reduce the flickering, it's normally not an issue until maximized.

public void drawBackgroundChild(PaintEventArgs e, Form form)
{
   // prevents error on resize
   if (form.ClientRectangle.Width == 0 || form.ClientRectangle.Height == 0)
       return;

   using (LinearGradientBrush brush = new LinearGradientBrush(form.ClientRectangle,
                                                                     UserSettings.secondaryColor1,
                                                                      UserSettings.secondaryColor2,
                                                                      90F))
            {
                e.Graphics.FillRectangle(brush, form.ClientRectangle);
            }
}



protected override CreateParams CreateParams
{
    get
    {
        var cp = base.CreateParams;
        cp.ExStyle |= 0x02000000;    // Turn on WS_EX_COMPOSITED
        return cp;
    }
}

I have tried the code above as well as the code below multiple times on the "Master" and "Child" Forms. Tested it out a bunch of different ways but no luck. Does anyone know if resizing the Windows Form disables Double Buffering or something to this extent?

 DoubleBuffered = true;
 this.SetStyle(ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.SupportsTransparentBackColor, true);
Ryan Johnson
  • 75
  • 11
  • a) what flickers? The form or the panel? b) try to use [this](https://stackoverflow.com/questions/44185298/update-datagridview-very-frequently/44188565#44188565) code to turn db on! c) no, resizing will certainly not turn db on or off. – TaW Jan 18 '19 at 16:58
  • @TaW The "Child" form inside the panel is what begins to flicker... I forgot to mention that this form inside the panel also has Paint Event, I'll update the post. – Ryan Johnson Jan 18 '19 at 17:04
  • @TaW DoubleBuffered is enabled for all forms being used and is not an issue until resized. The only thing that I can think of is that the panel holder for the "Child" forms does not have double buffered specifically enabled for that control, and that somehow resizing affects it but idk – Ryan Johnson Jan 18 '19 at 17:15

1 Answers1

1

Had to remove any sort of double buffering / createparams etc. from the master form, and put it exclusively into the child forms....

protected override CreateParams CreateParams
{
    get
       {
         var cp = base.CreateParams;
         cp.ExStyle |= 0x02000000;    // Turn on WS_EX_COMPOSITED
         return cp;
       }
}


frmChild()
{
    ResizeRedraw = true;
    this.SetStyle(ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer |
                  ControlStyles.AllPaintingInWmPaint | ControlStyles.SupportsTransparentBackColor, true);
}
Ryan Johnson
  • 75
  • 11