title: Unable to create a button gradient in c#
body: <p>I am trying to add a gradient in c# by extending the System.Windows.Forms.button class. The problem I'm having is that it doesn't add the gradient to the button either in design or runtime, though the designer does pick up the color1, color2, and angle fields, so it's definitely overridden and instantiated correctly. Am I missing something ? </p>
  
  <pre><code>class ps_button : System.Windows.Forms.Button
  {
      private Color _Color1 = Color.FromArgb(255, 224, 138, 25);
      private Color _Color2 = Color.FromArgb(255, 245, 202, 134);
      private float _ColorAngle = 45f;
  
      public Color Color1
      {
          get { return _Color1; }
          set
          {
              _Color1 = value;
              this.Invalidate(); // Tell the Form to repaint itself
          }
      }
  
      public Color Color2
      {
          get { return _Color2; }
          set
          {
              _Color2 = value;
              this.Invalidate(); // Tell the Form to repaint itself
          }
      }
  
      public float ColorAngle
      {
          get { return _ColorAngle; }
          set
          {
              _ColorAngle = value;
              this.Invalidate(); // Tell the Form to repaint itself
          }
  
      }
      protected override void OnPaintBackground(PaintEventArgs pevent)
      {
          // Getting the graphics object
          Graphics g = pevent.Graphics;
  
          // Creating the rectangle for the gradient
          Rectangle rBackground = new Rectangle(0, 0,
                                    this.Width, this.Height);
  
          // Creating the lineargradient
          System.Drawing.Drawing2D.LinearGradientBrush bBackground
              = new System.Drawing.Drawing2D.LinearGradientBrush(rBackground,
                                                _Color1, _Color2, _ColorAngle);
  
          // Draw the gradient onto the form
          g.FillRectangle(bBackground, rBackground);
  
          // Disposing of the resources held by the brush
          bBackground.Dispose();
      }
  }
  </code></pre>