Gradient Panel shows red cross when minimized and then restored

前端 未结 3 1309
感情败类
感情败类 2021-01-16 06:14

I have no idea why this is happening, but I created the below code which is a gradient panel, the panel is then docked to the left of the screen.

When the form is re

3条回答
  •  情书的邮戳
    2021-01-16 07:02

    I'm doing something similar, but even cleaning up the LinearGradientBrush didn't fix it for me. Looking at the console output, I noticed "A first chance exception of type System.ArgumentException occurred in System.Drawing.dll." I believe this is because the ClientRectangle is 0,0 when the component is minimized. Adding this code seemed to fix it for me:

      protected override void OnPaintBackground(PaintEventArgs e)
      {
         base.OnPaintBackground(e);
         if (this.gradientBrush != null)
            this.gradientBrush.Dispose();
         if (this.ClientRectangle.Width > 0 && this.ClientRectangle.Height > 0)
         {
            this.gradientBrush = new LinearGradientBrush(this.ClientRectangle,
               FROM_GRADIENT_COLOR, TO_GRADIENT_COLOR, LinearGradientMode.Horizontal);
    
            e.Graphics.FillRectangle(this.gradientBrush, this.ClientRectangle);
         }
      }
    

提交回复
热议问题