ButtonRenderer.DrawButton メソッド

定義

ボタン コントロールを描画します。

オーバーロード

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)

状態と境界を指定してボタン コントロールを描画します。

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 値の 1 つ。

注釈

オペレーティング システムでビジュアル スタイルが有効になっており、ビジュアル スタイルが現在のアプリケーションに適用されている場合、このメソッドは現在のビジュアル スタイルでボタンを描画します。 それ以外の場合は、従来の Windows スタイルでボタンが描画されます。

適用対象

DrawButton(Graphics, Rectangle, Boolean, PushButtonState)

状態、境界、およびオプションでフォーカスを示す四角形を指定して、ボタン コントロールを描画します。

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 値の 1 つ。

注釈

オペレーティング システムでビジュアル スタイルが有効になっており、ビジュアル スタイルが現在のアプリケーションに適用されている場合、このメソッドは現在のビジュアル スタイルでボタンを描画します。 それ以外の場合は、従来の Windows スタイルでボタンが描画されます。

適用対象

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

状態と境界、使用するイメージ、およびオプションでフォーカスを示す四角形を指定して、ボタン コントロールを描画します。

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

image の大きさを表す Rectangle

focused
Boolean

フォーカスを示す四角形をボタンに描画する場合は true。それ以外の場合は false

state
PushButtonState

ボタンの表示状態を指定する PushButtonState 値の 1 つ。

注釈

オペレーティング システムでビジュアル スタイルが有効になっており、ビジュアル スタイルが現在のアプリケーションに適用されている場合、このメソッドは現在のビジュアル スタイルでボタンを描画します。 それ以外の場合は、従来の Windows スタイルでボタンが描画されます。

適用対象

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

状態と境界、使用するテキスト、およびオプションでフォーカスを示す四角形を指定して、ボタン コントロールを描画します。

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

buttonText に適用する Font

focused
Boolean

フォーカスを示す四角形をボタンに描画する場合は true。それ以外の場合は false

state
PushButtonState

ボタンの表示状態を指定する PushButtonState 値の 1 つ。

次のコード例では、 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)

状態と境界、使用するテキストとテキストの書式指定、およびオプションでフォーカスを示す四角形を指定して、ボタン コントロールを描画します。

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

buttonText に適用する Font

flags
TextFormatFlags

buttonText に適用する TextFormatFlags 値のビットごとの組み合わせ。

focused
Boolean

フォーカスを示す四角形をボタンに描画する場合は true。それ以外の場合は false

state
PushButtonState

ボタンの表示状態を指定する PushButtonState 値の 1 つ。

注釈

オペレーティング システムでビジュアル スタイルが有効になっており、ビジュアル スタイルが現在のアプリケーションに適用されている場合、このメソッドは現在のビジュアル スタイルでボタンを描画します。 それ以外の場合は、従来の Windows スタイルでボタンが描画されます。

適用対象

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

状態と位置、使用するテキストとイメージ、およびオプションでフォーカスを示す四角形を指定して、ボタン コントロールを描画します。

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

buttonText に適用する Font

image
Image

ボタン上に描画する Image

imageBounds
Rectangle

image の大きさを表す Rectangle

focused
Boolean

フォーカスを示す四角形をボタンに描画する場合は true。それ以外の場合は false

state
PushButtonState

ボタンの表示状態を指定する PushButtonState 値の 1 つ。

注釈

オペレーティング システムでビジュアル スタイルが有効になっており、ビジュアル スタイルが現在のアプリケーションに適用されている場合、このメソッドは現在のビジュアル スタイルでボタンを描画します。 それ以外の場合は、従来の Windows スタイルでボタンが描画されます。

適用対象

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

状態と境界、使用するテキスト、テキストの書式指定、イメージ、およびオプションでフォーカスを示す四角形を指定して、ボタン コントロールを描画します。

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

buttonText に適用する Font

flags
TextFormatFlags

buttonText に適用する TextFormatFlags 値のビットごとの組み合わせ。

image
Image

ボタン上に描画する Image

imageBounds
Rectangle

image の大きさを表す Rectangle

focused
Boolean

フォーカスを示す四角形をボタンに描画する場合は true。それ以外の場合は false

state
PushButtonState

ボタンの表示状態を指定する PushButtonState 値の 1 つ。

注釈

オペレーティング システムでビジュアル スタイルが有効になっており、ビジュアル スタイルが現在のアプリケーションに適用されている場合、このメソッドは現在のビジュアル スタイルでボタンを描画します。 それ以外の場合は、従来の Windows スタイルでボタンが描画されます。

適用対象