ControlPaint.DrawButton 方法

定义

绘制按钮控件。

重载

DrawButton(Graphics, Rectangle, ButtonState)

在指定的边界内、指定的图形表面上,绘制处于指定状态的按钮控件。

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

在指定的边界内、指定的图形表面上,绘制处于指定状态的按钮控件。

DrawButton(Graphics, Rectangle, ButtonState)

在指定的边界内、指定的图形表面上,绘制处于指定状态的按钮控件。

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

参数

graphics
Graphics

要进行绘制的 Graphics

rectangle
Rectangle

代表按钮尺寸的 Rectangle

state
ButtonState

ButtonState 值的按位组合,指定将按钮画入的状态。

另请参阅

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.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)

在指定的边界内、指定的图形表面上,绘制处于指定状态的按钮控件。

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

参数

graphics
Graphics

要进行绘制的 Graphics

x
Int32

所绘制矩形左上角的 x 坐标。

y
Int32

所绘制矩形左上角的 y 坐标。

width
Int32

按钮的宽度。

height
Int32

按钮的高度。

state
ButtonState

ButtonState 值的按位组合,指定将按钮画入的状态。

示例

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);
    }

}

另请参阅

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.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