ControlPaint.DrawButton Method

Definition

Draws a button control.

Overloads

DrawButton(Graphics, Rectangle, ButtonState)

Draws a button control in the specified state, on the specified graphics surface, and within the specified bounds.

DrawButton(Graphics, Int32, Int32, Int32, Int32, ButtonState)

Draws a button control in the specified state, on the specified graphics surface, and within the specified bounds.

DrawButton(Graphics, Rectangle, ButtonState)

Source:
ControlPaint.cs
Source:
ControlPaint.cs
Source:
ControlPaint.cs

Draws a button control in the specified state, on the specified graphics surface, and within the specified bounds.

C#
public static void DrawButton(System.Drawing.Graphics graphics, System.Drawing.Rectangle rectangle, System.Windows.Forms.ButtonState state);

Parameters

graphics
Graphics

The Graphics to draw on.

rectangle
Rectangle

The Rectangle that represents the dimensions of the button.

state
ButtonState

A bitwise combination of the ButtonState values that specifies the state to draw the button in.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

DrawButton(Graphics, Int32, Int32, Int32, Int32, ButtonState)

Source:
ControlPaint.cs
Source:
ControlPaint.cs
Source:
ControlPaint.cs

Draws a button control in the specified state, on the specified graphics surface, and within the specified bounds.

C#
public static void DrawButton(System.Drawing.Graphics graphics, int x, int y, int width, int height, System.Windows.Forms.ButtonState state);

Parameters

graphics
Graphics

The Graphics to draw on.

x
Int32

The x-coordinate of the upper left corner of the drawing rectangle.

y
Int32

The y-coordinate of the upper left corner of the drawing rectangle.

width
Int32

The width of the button.

height
Int32

The height of the button.

state
ButtonState

A bitwise combination of the ButtonState values that specifies the state to draw the button in.

Examples

C#
using System;
using System.Drawing;
using System.Windows.Forms;

public class Form1 : Form
{
    private Button _button1 = new Button();
    private Button _button2 = new Button();

    [STAThread]
    static void Main()
    {
        Application.Run(new Form1());
    }

    public Form1()
    {
        _button2.Location = new Point(0, _button1.Height + 10);
        this.Click += Button2_Click;
        this.Controls.Add(_button1);
        this.Controls.Add(_button2);
    }

    private void Button2_Click(object sender, System.EventArgs e)
    {
        // Draws a flat button on button1.
        ControlPaint.DrawButton(
            System.Drawing.Graphics.FromHwnd(_button1.Handle), 0, 0,
            _button1.Width, _button1.Height,
            ButtonState.Flat);
    }

}

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9