Live Chat Icon For mobile
Live Chat Icon

How do I add custom drawing to a Button?

Platform: WPF| Category: Buttons

‘Subclass Button’ and adding a custom ‘Paint’ event handler lets you do this.

[C#]
 
public class CustomButton : Button
{
  public CustomButton()
  {
    Paint += new PaintEventHandler( ButtonPaint );
  }

  private void ButtonPaint( object sender, PaintEventArgs e )
  {
    Pen pen = new Pen( Color.Red );
    pen.Width = 8;
    e.Graphics.DrawLine( pen, 7, 4, 7, Height - 4 );
    pen.Width = 1;
    e.Graphics.DrawEllipse( pen, Width - 16 , 6, 8, 8 );
  }
}

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.