ButtonRenderer.DrawButton 方法

定義

畫出按鈕控制。

多載

名稱 Description
DrawButton(Graphics, Rectangle, PushButtonState)

在指定的狀態和界限下繪製一個按鈕控制項。

DrawButton(Graphics, Rectangle, Boolean, PushButtonState)

在指定的狀態和邊界下繪製按鈕控制,並附帶可選的焦點矩形。

DrawButton(Graphics, Rectangle, Image, Rectangle, Boolean, PushButtonState)

在指定的狀態和邊界下繪製按鈕控制項,並附上指定的圖片,並附帶可選的對焦矩形。

DrawButton(Graphics, Rectangle, String, Font, Boolean, PushButtonState)

在指定狀態和邊界下繪製按鈕控制項,包含指定的文字,並附帶可選的焦點矩形。

DrawButton(Graphics, Rectangle, String, Font, TextFormatFlags, Boolean, PushButtonState)

在指定的狀態與邊界繪製按鈕控制項,並符合指定的文字與文字格式,並可選地使用焦點矩形。

DrawButton(Graphics, Rectangle, String, Font, Image, Rectangle, Boolean, PushButtonState)

在指定的狀態與邊界繪製按鈕控制項,並附上指定的文字與圖片,並可選地使用焦點矩形。

DrawButton(Graphics, Rectangle, String, Font, TextFormatFlags, Image, Rectangle, Boolean, PushButtonState)

在指定狀態和界限下繪製按鈕控制項;包含指定的文字、文字格式與圖片;並可選配對焦矩形。

DrawButton(Graphics, Rectangle, PushButtonState)

來源:
ButtonRenderer.cs
來源:
ButtonRenderer.cs
來源:
ButtonRenderer.cs
來源:
ButtonRenderer.cs
來源:
ButtonRenderer.cs

在指定的狀態和界限下繪製一個按鈕控制項。

public:
 static void DrawButton(System::Drawing::Graphics ^ g, System::Drawing::Rectangle bounds, System::Windows::Forms::VisualStyles::PushButtonState state);
public static void DrawButton(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.VisualStyles.PushButtonState state);
static member DrawButton : System.Drawing.Graphics * System.Drawing.Rectangle * System.Windows.Forms.VisualStyles.PushButtonState -> unit
Public Shared Sub DrawButton (g As Graphics, bounds As Rectangle, state As PushButtonState)

參數

g
Graphics

他們 Graphics 用來畫按鈕。

bounds
Rectangle

Rectangle 個按鈕的範圍。

state
PushButtonState

PushButtonState其中一個值是指定按鈕視覺狀態的。

備註

若作業系統啟用視覺樣式,且套用視覺風格於目前應用程式,此方法會繪製出目前視覺風格的按鈕。 否則,按鈕會以經典的 Windows 風格繪製。

適用於

DrawButton(Graphics, Rectangle, Boolean, PushButtonState)

來源:
ButtonRenderer.cs
來源:
ButtonRenderer.cs
來源:
ButtonRenderer.cs
來源:
ButtonRenderer.cs
來源:
ButtonRenderer.cs

在指定的狀態和邊界下繪製按鈕控制,並附帶可選的焦點矩形。

public:
 static void DrawButton(System::Drawing::Graphics ^ g, System::Drawing::Rectangle bounds, bool focused, System::Windows::Forms::VisualStyles::PushButtonState state);
public static void DrawButton(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, bool focused, System.Windows.Forms.VisualStyles.PushButtonState state);
static member DrawButton : System.Drawing.Graphics * System.Drawing.Rectangle * bool * System.Windows.Forms.VisualStyles.PushButtonState -> unit
Public Shared Sub DrawButton (g As Graphics, bounds As Rectangle, focused As Boolean, state As PushButtonState)

參數

g
Graphics

他們 Graphics 用來畫按鈕。

bounds
Rectangle

Rectangle 個按鈕的範圍。

focused
Boolean

true在按鈕上畫出焦點矩形;否則,。 false

state
PushButtonState

PushButtonState其中一個值是指定按鈕視覺狀態的。

備註

若作業系統啟用視覺樣式,且套用視覺風格於目前應用程式,此方法會繪製出目前視覺風格的按鈕。 否則,按鈕會以經典的 Windows 風格繪製。

適用於

DrawButton(Graphics, Rectangle, Image, Rectangle, Boolean, PushButtonState)

來源:
ButtonRenderer.cs
來源:
ButtonRenderer.cs
來源:
ButtonRenderer.cs
來源:
ButtonRenderer.cs
來源:
ButtonRenderer.cs

在指定的狀態和邊界下繪製按鈕控制項,並附上指定的圖片,並附帶可選的對焦矩形。

public:
 static void DrawButton(System::Drawing::Graphics ^ g, System::Drawing::Rectangle bounds, System::Drawing::Image ^ image, System::Drawing::Rectangle imageBounds, bool focused, System::Windows::Forms::VisualStyles::PushButtonState state);
public static void DrawButton(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Drawing.Image image, System.Drawing.Rectangle imageBounds, bool focused, System.Windows.Forms.VisualStyles.PushButtonState state);
static member DrawButton : System.Drawing.Graphics * System.Drawing.Rectangle * System.Drawing.Image * System.Drawing.Rectangle * bool * System.Windows.Forms.VisualStyles.PushButtonState -> unit
Public Shared Sub DrawButton (g As Graphics, bounds As Rectangle, image As Image, imageBounds As Rectangle, focused As Boolean, state As PushButtonState)

參數

g
Graphics

他們 Graphics 用來畫按鈕。

bounds
Rectangle

Rectangle 個按鈕的範圍。

image
Image

Image 按鈕上畫畫。

imageBounds
Rectangle

Rectangle 代表 的 image維度。

focused
Boolean

true在按鈕上畫出焦點矩形;否則,。 false

state
PushButtonState

PushButtonState其中一個值是指定按鈕視覺狀態的。

備註

若作業系統啟用視覺樣式,且套用視覺風格於目前應用程式,此方法會繪製出目前視覺風格的按鈕。 否則,按鈕會以經典的 Windows 風格繪製。

適用於

DrawButton(Graphics, Rectangle, String, Font, Boolean, PushButtonState)

來源:
ButtonRenderer.cs
來源:
ButtonRenderer.cs
來源:
ButtonRenderer.cs
來源:
ButtonRenderer.cs
來源:
ButtonRenderer.cs

在指定狀態和邊界下繪製按鈕控制項,包含指定的文字,並附帶可選的焦點矩形。

public:
 static void DrawButton(System::Drawing::Graphics ^ g, System::Drawing::Rectangle bounds, System::String ^ buttonText, System::Drawing::Font ^ font, bool focused, System::Windows::Forms::VisualStyles::PushButtonState state);
public static void DrawButton(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, string buttonText, System.Drawing.Font font, bool focused, System.Windows.Forms.VisualStyles.PushButtonState state);
public static void DrawButton(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, string? buttonText, System.Drawing.Font? font, bool focused, System.Windows.Forms.VisualStyles.PushButtonState state);
static member DrawButton : System.Drawing.Graphics * System.Drawing.Rectangle * string * System.Drawing.Font * bool * System.Windows.Forms.VisualStyles.PushButtonState -> unit
Public Shared Sub DrawButton (g As Graphics, bounds As Rectangle, buttonText As String, font As Font, focused As Boolean, state As PushButtonState)

參數

g
Graphics

他們 Graphics 用來畫按鈕。

bounds
Rectangle

Rectangle 個按鈕的範圍。

buttonText
String

String 按鈕上畫畫。

font
Font

Font 應用於 buttonText

focused
Boolean

true在按鈕上畫出焦點矩形;否則,。 false

state
PushButtonState

PushButtonState其中一個值是指定按鈕視覺狀態的。

範例

以下程式碼範例使用 DrawButton(Graphics, Rectangle, String, Font, Boolean, PushButtonState) 自訂控制項 OnPaint 的方法,在滑鼠指標位置決定的狀態中繪製按鈕。 此程式碼範例是本類別更大範例 ButtonRenderer 的一部分。

    // Draw the large or small button, depending on the current state.
protected:
    virtual void OnPaint(PaintEventArgs^ e) override
    {
        __super::OnPaint(e);

        // Draw the smaller pressed button image
        if (state == PushButtonState::Pressed)
        {
            // Set the background color to the parent if visual styles
            // are disabled, because DrawParentBackground will only paint
            // over the control background if visual styles are enabled.
            if (Application::RenderWithVisualStyles)
            {
                this->BackColor = Color::Azure;
            }
            else
            {
                this->BackColor = this->Parent->BackColor;
            }


            // If you comment out the call to DrawParentBackground,
            // the background of the control will still be visible
            // outside the pressed button, if visual styles are enabled.
            ButtonRenderer::DrawParentBackground(e->Graphics,
                ClientRectangle, this);
            ButtonRenderer::DrawButton(e->Graphics, ClickRectangle,
                this->Text, this->Font, true, state);
        }

        // Draw the bigger unpressed button image.
        else
        {
            ButtonRenderer::DrawButton(e->Graphics, ClientRectangle,
                this->Text, this->Font, false, state);
        }
    }

    // Draw the smaller pressed button image.
protected:
    virtual void OnMouseDown(MouseEventArgs^ e) override
    {
        __super::OnMouseDown(e);
        this->Text = "Clicked!";
        state = PushButtonState::Pressed;
        Invalidate();
    }

    // Draw the button in the hot state.
protected:
    virtual void OnMouseEnter(EventArgs^ e) override
    {
        __super::OnMouseEnter(e);
        this->Text = "Click here";
        state = PushButtonState::Hot;
        Invalidate();
    }

    // Draw the button in the unpressed state.
protected:
    virtual void OnMouseLeave(EventArgs^ e) override
    {
        __super::OnMouseLeave(e);
        this->Text = "Click here";
        state = PushButtonState::Normal;
        Invalidate();
    }
// Draw the large or small button, depending on the current state.
protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);

    // Draw the smaller pressed button image
    if (state == PushButtonState.Pressed)
    {
        // Set the background color to the parent if visual styles  
        // are disabled, because DrawParentBackground will only paint  
        // over the control background if visual styles are enabled.
        this.BackColor = Application.RenderWithVisualStyles ?
            Color.Azure : this.Parent.BackColor;

        // If you comment out the call to DrawParentBackground, 
        // the background of the control will still be visible 
        // outside the pressed button, if visual styles are enabled.
        ButtonRenderer.DrawParentBackground(e.Graphics,
            ClientRectangle, this);
        ButtonRenderer.DrawButton(e.Graphics, ClickRectangle,
            this.Text, this.Font, true, state);
    }

    // Draw the bigger unpressed button image.
    else
    {
        ButtonRenderer.DrawButton(e.Graphics, ClientRectangle,
            this.Text, this.Font, false, state);
    }
}

// Draw the smaller pressed button image.
protected override void OnMouseDown(MouseEventArgs e)
{
    base.OnMouseDown(e);
    this.Text = "Clicked!";
    state = PushButtonState.Pressed;
    Invalidate();
}

// Draw the button in the hot state. 
protected override void OnMouseEnter(EventArgs e)
{
    base.OnMouseEnter(e);
    this.Text = "Click here";
    state = PushButtonState.Hot;
    Invalidate();
}

// Draw the button in the unpressed state.
protected override void OnMouseLeave(EventArgs e)
{
    base.OnMouseLeave(e);
    this.Text = "Click here";
    state = PushButtonState.Normal;
    Invalidate();
}
' Draw the large or small button, depending on the current state.
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
    MyBase.OnPaint(e)

    ' Draw the smaller pressed button image.
    If state = PushButtonState.Pressed Then
        ' Set the background color to the parent if visual styles  
        ' are disabled, because DrawParentBackground will only paint  
        ' over the control background if visual styles are enabled.
        If Application.RenderWithVisualStyles Then
            Me.BackColor = Color.Azure
        Else
            Me.BackColor = Me.Parent.BackColor
        End If

        ' If you comment out the call to DrawParentBackground,   
        ' the background of the control will still be visible 
        ' outside the pressed button, if visual styles are enabled.
        ButtonRenderer.DrawParentBackground(e.Graphics, _
            Me.ClientRectangle, Me)
        ButtonRenderer.DrawButton(e.Graphics, ClickRectangle, _
            Me.Text, Me.Font, True, state)

    ' Draw the bigger unpressed button image.
    Else
        ButtonRenderer.DrawButton(e.Graphics, Me.ClientRectangle, _
            Me.Text, Me.Font, False, state)
    End If
End Sub

' Draw the smaller pressed button image.
Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
    MyBase.OnMouseDown(e)
    With Me
        .Text = "Clicked!"
        .state = PushButtonState.Pressed
    End With
    Invalidate()
End Sub

' Draw the button in the hot state. 
Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
    MyBase.OnMouseEnter(e)
    With Me
        .Text = "Click here"
        .state = PushButtonState.Hot
    End With
    Invalidate()
End Sub

' Draw the button in the unpressed state.
Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
    MyBase.OnMouseLeave(e)
    With Me
        .Text = "Click here"
        .state = PushButtonState.Normal
    End With
    Invalidate()
End Sub

備註

若作業系統啟用視覺樣式,且套用視覺風格於目前應用程式,此方法會繪製出目前視覺風格的按鈕。 否則,按鈕會以經典的 Windows 風格繪製。

適用於

DrawButton(Graphics, Rectangle, String, Font, TextFormatFlags, Boolean, PushButtonState)

來源:
ButtonRenderer.cs
來源:
ButtonRenderer.cs
來源:
ButtonRenderer.cs
來源:
ButtonRenderer.cs
來源:
ButtonRenderer.cs

在指定的狀態與邊界繪製按鈕控制項,並符合指定的文字與文字格式,並可選地使用焦點矩形。

public:
 static void DrawButton(System::Drawing::Graphics ^ g, System::Drawing::Rectangle bounds, System::String ^ buttonText, System::Drawing::Font ^ font, System::Windows::Forms::TextFormatFlags flags, bool focused, System::Windows::Forms::VisualStyles::PushButtonState state);
public static void DrawButton(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, string buttonText, System.Drawing.Font font, System.Windows.Forms.TextFormatFlags flags, bool focused, System.Windows.Forms.VisualStyles.PushButtonState state);
public static void DrawButton(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, string? buttonText, System.Drawing.Font? font, System.Windows.Forms.TextFormatFlags flags, bool focused, System.Windows.Forms.VisualStyles.PushButtonState state);
static member DrawButton : System.Drawing.Graphics * System.Drawing.Rectangle * string * System.Drawing.Font * System.Windows.Forms.TextFormatFlags * bool * System.Windows.Forms.VisualStyles.PushButtonState -> unit
Public Shared Sub DrawButton (g As Graphics, bounds As Rectangle, buttonText As String, font As Font, flags As TextFormatFlags, focused As Boolean, state As PushButtonState)

參數

g
Graphics

他們 Graphics 用來畫按鈕。

bounds
Rectangle

Rectangle 個按鈕的範圍。

buttonText
String

String 按鈕上畫畫。

font
Font

Font 應用於 buttonText

flags
TextFormatFlags

一個以位元組合 TextFormatFlags 的數值,應用於 buttonText

focused
Boolean

true在按鈕上畫出焦點矩形;否則,。 false

state
PushButtonState

PushButtonState其中一個值是指定按鈕視覺狀態的。

備註

若作業系統啟用視覺樣式,且套用視覺風格於目前應用程式,此方法會繪製出目前視覺風格的按鈕。 否則,按鈕會以經典的 Windows 風格繪製。

適用於

DrawButton(Graphics, Rectangle, String, Font, Image, Rectangle, Boolean, PushButtonState)

來源:
ButtonRenderer.cs
來源:
ButtonRenderer.cs
來源:
ButtonRenderer.cs
來源:
ButtonRenderer.cs
來源:
ButtonRenderer.cs

在指定的狀態與邊界繪製按鈕控制項,並附上指定的文字與圖片,並可選地使用焦點矩形。

public:
 static void DrawButton(System::Drawing::Graphics ^ g, System::Drawing::Rectangle bounds, System::String ^ buttonText, System::Drawing::Font ^ font, System::Drawing::Image ^ image, System::Drawing::Rectangle imageBounds, bool focused, System::Windows::Forms::VisualStyles::PushButtonState state);
public static void DrawButton(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, string buttonText, System.Drawing.Font font, System.Drawing.Image image, System.Drawing.Rectangle imageBounds, bool focused, System.Windows.Forms.VisualStyles.PushButtonState state);
public static void DrawButton(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, string? buttonText, System.Drawing.Font? font, System.Drawing.Image image, System.Drawing.Rectangle imageBounds, bool focused, System.Windows.Forms.VisualStyles.PushButtonState state);
static member DrawButton : System.Drawing.Graphics * System.Drawing.Rectangle * string * System.Drawing.Font * System.Drawing.Image * System.Drawing.Rectangle * bool * System.Windows.Forms.VisualStyles.PushButtonState -> unit
Public Shared Sub DrawButton (g As Graphics, bounds As Rectangle, buttonText As String, font As Font, image As Image, imageBounds As Rectangle, focused As Boolean, state As PushButtonState)

參數

g
Graphics

他們 Graphics 用來畫按鈕。

bounds
Rectangle

Rectangle 個按鈕的範圍。

buttonText
String

String 按鈕上畫畫。

font
Font

Font 應用於 buttonText

image
Image

Image 按鈕上畫畫。

imageBounds
Rectangle

Rectangle 代表 的 image維度。

focused
Boolean

true在按鈕上畫出焦點矩形;否則,。 false

state
PushButtonState

PushButtonState其中一個值是指定按鈕視覺狀態的。

備註

若作業系統啟用視覺樣式,且套用視覺風格於目前應用程式,此方法會繪製出目前視覺風格的按鈕。 否則,按鈕會以經典的 Windows 風格繪製。

適用於

DrawButton(Graphics, Rectangle, String, Font, TextFormatFlags, Image, Rectangle, Boolean, PushButtonState)

來源:
ButtonRenderer.cs
來源:
ButtonRenderer.cs
來源:
ButtonRenderer.cs
來源:
ButtonRenderer.cs
來源:
ButtonRenderer.cs

在指定狀態和界限下繪製按鈕控制項;包含指定的文字、文字格式與圖片;並可選配對焦矩形。

public:
 static void DrawButton(System::Drawing::Graphics ^ g, System::Drawing::Rectangle bounds, System::String ^ buttonText, System::Drawing::Font ^ font, System::Windows::Forms::TextFormatFlags flags, System::Drawing::Image ^ image, System::Drawing::Rectangle imageBounds, bool focused, System::Windows::Forms::VisualStyles::PushButtonState state);
public static void DrawButton(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, string buttonText, System.Drawing.Font font, System.Windows.Forms.TextFormatFlags flags, System.Drawing.Image image, System.Drawing.Rectangle imageBounds, bool focused, System.Windows.Forms.VisualStyles.PushButtonState state);
public static void DrawButton(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, string? buttonText, System.Drawing.Font? font, System.Windows.Forms.TextFormatFlags flags, System.Drawing.Image image, System.Drawing.Rectangle imageBounds, bool focused, System.Windows.Forms.VisualStyles.PushButtonState state);
static member DrawButton : System.Drawing.Graphics * System.Drawing.Rectangle * string * System.Drawing.Font * System.Windows.Forms.TextFormatFlags * System.Drawing.Image * System.Drawing.Rectangle * bool * System.Windows.Forms.VisualStyles.PushButtonState -> unit
Public Shared Sub DrawButton (g As Graphics, bounds As Rectangle, buttonText As String, font As Font, flags As TextFormatFlags, image As Image, imageBounds As Rectangle, focused As Boolean, state As PushButtonState)

參數

g
Graphics

他們 Graphics 用來畫按鈕。

bounds
Rectangle

Rectangle 個按鈕的範圍。

buttonText
String

String 按鈕上畫畫。

font
Font

Font 應用於 buttonText

flags
TextFormatFlags

一個以位元組合 TextFormatFlags 的數值,應用於 buttonText

image
Image

Image 按鈕上畫畫。

imageBounds
Rectangle

Rectangle 代表 的 image維度。

focused
Boolean

true在按鈕上畫出焦點矩形;否則,。 false

state
PushButtonState

PushButtonState其中一個值是指定按鈕視覺狀態的。

備註

若作業系統啟用視覺樣式,且套用視覺風格於目前應用程式,此方法會繪製出目前視覺風格的按鈕。 否則,按鈕會以經典的 Windows 風格繪製。

適用於