次の方法で共有


ControlPaint クラス

共通の Windows コントロールとその要素を描画するために使用するメソッドを提供します。

この型のすべてのメンバの一覧については、ControlPaint メンバ を参照してください。

System.Object
   System.Windows.Forms.ControlPaint

NotInheritable Public Class ControlPaint
[C#]
public sealed class ControlPaint
[C++]
public __gc __sealed class ControlPaint
[JScript]
public class ControlPaint

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

解説

ControlPaint クラスに格納されているメソッドを使用すると、独自のコントロールまたはコントロールの要素を描画できます。コントロールについて UserPaint ビットを true に設定すると、独自のコントロールを描画できるようになります。 Control.GetStyle メソッドまたは Control.SetStyle メソッドを呼び出すと、そのスタイル ビットを取得または設定できます。任意のコントロールについて複数のスタイル ビットを設定できます。 ControlStyles 列挙体メンバは、ビットごとの演算と組み合わせることができます。

使用例

 
Imports System
Imports System.Drawing
Imports System.Windows.Forms

    Public Class Form1
        Inherits System.Windows.Forms.Form

        Private button1 As System.Windows.Forms.Button = New Button
        Private button2 As System.Windows.Forms.Button = New Button

        <System.STAThreadAttribute()>  _
        Public Shared Sub Main()
            System.Windows.Forms.Application.Run(New Form1)
        End Sub

        Public Sub New()
            Me.button2.Location = New Point(0, button1.Height + 10)
            AddHandler Me.button2.Click, AddressOf Me.button2_Click
            Me.Controls.Add(Me.button1)
            Me.Controls.Add(Me.button2)
        End Sub

        Private Sub button2_Click(sender As Object, e As System.EventArgs)
            ' Draws a flat button on button1.
            ControlPaint.DrawButton(System.Drawing.Graphics.FromHwnd(button1.Handle), 0, 0, button1.Width, button1.Height, ButtonState.Flat)
        End Sub 'button2_Click
End Class

[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(){
        this.button2.Location = new Point(0, button1.Height + 10);
        this.Click += new EventHandler(this.button2_Click);
        this.Controls.Add(this.button1);
        this.Controls.Add(this.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);
    }
}

[C++] 
#using <mscorlib.dll>
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;

public __gc class Form1 : public Form {

private:
    Button* button1;
    Button* button2;

public:
    Form1() {
        button1 = new Button();
        button2 = new Button();

        this->button2->Location = Point(0, button1->Height + 10);
        this->Click += new EventHandler(this, &Form1::button2_Click);
        this->Controls->Add(this->button1);
        this->Controls->Add(this->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);
    }
};

[STAThread]
void main() {
    Application::Run(new Form1());
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Windows.Forms

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

アセンブリ: System.Windows.Forms (System.Windows.Forms.dll 内)

参照

ControlPaint メンバ | System.Windows.Forms 名前空間 | Control | ControlStyles