ControlPaintとは? わかりやすく解説

Control.Paint イベント

コントロールが再描画されると発生します。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Event Paint As PaintEventHandler
Dim instance As Control
Dim handler As PaintEventHandler

AddHandler instance.Paint, handler
public event PaintEventHandler Paint
public:
event PaintEventHandler^ Paint {
    void add (PaintEventHandler^ value);
    void remove (PaintEventHandler^ value);
}
/** @event */
public void add_Paint (PaintEventHandler value)

/** @event */
public void remove_Paint (PaintEventHandler
 value)
JScript では、イベントは使用できますが、新規に宣言することはできません。
解説解説
使用例使用例

フォーム上で PictureBox コントロールを作成し、Paint イベントを使用して描画するコード例を次に示します。

' This example creates a PictureBox control on the form and draws to
 it. 
' This example assumes that the Form_Load event handler method is connected
 
' to the Load event of the form.
Private pictureBox1 As New
 PictureBox()

Private Sub Form1_Load(ByVal
 sender As Object, ByVal
 e As System.EventArgs) Handles MyBase.Load
    ' Dock the PictureBox to the form and set its background to white.
    pictureBox1.Dock = DockStyle.Fill
    pictureBox1.BackColor = Color.White
    ' Connect the Paint event of the PictureBox to the event handler
 method.
    AddHandler pictureBox1.Paint, AddressOf
 Me.pictureBox1_Paint

    ' Add the PictureBox control to the Form.
    Me.Controls.Add(pictureBox1)
End Sub 'Form1_Load


Private Sub pictureBox1_Paint(ByVal
 sender As Object, ByVal
 e As System.Windows.Forms.PaintEventArgs)
    ' Create a local version of the graphics object for the PictureBox.
    Dim g As Graphics = e.Graphics

    ' Draw a string on the PictureBox.
    g.DrawString("This is a diagonal line drawn on the control",
 _
        New Font("Arial", 10),
 Brushes.Red, New PointF(30.0F, 30.0F))
    ' Draw a line in the PictureBox.
    g.DrawLine(System.Drawing.Pens.Red, pictureBox1.Left, _ 
        pictureBox1.Top, pictureBox1.Right, pictureBox1.Bottom)
End Sub 'pictureBox1_Paint
// This example creates a PictureBox control on the form and draws to
 it.
// This example assumes that the Form_Load event handler method is
// connected to the Load event of the form.

private PictureBox pictureBox1 = new PictureBox();
private void Form1_Load(object sender, System.EventArgs
 e)
{
    // Dock the PictureBox to the form and set its background to white.
    pictureBox1.Dock = DockStyle.Fill;
    pictureBox1.BackColor = Color.White;
    // Connect the Paint event of the PictureBox to the event handler
 method.
    pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);

    // Add the PictureBox control to the Form.
    this.Controls.Add(pictureBox1);
}

private void pictureBox1_Paint(object sender,
 System.Windows.Forms.PaintEventArgs e)
{
    // Create a local version of the graphics object for the PictureBox.
    Graphics g = e.Graphics;

    // Draw a string on the PictureBox.
    g.DrawString("This is a diagonal line drawn on the control",
        new Font("Arial",10), System.Drawing.Brushes.Blue,
 new Point(30,30));
    // Draw a line in the PictureBox.
    g.DrawLine(System.Drawing.Pens.Red, pictureBox1.Left, pictureBox1.Top,
        pictureBox1.Right, pictureBox1.Bottom);
}
   // This example creates a PictureBox control on the form and draws to
 it.
   // This example assumes that the Form_Load event handler method is
   // connected to the Load event of the form.
private:
   PictureBox^ pictureBox1;
   void Form1_Load( Object^ /*sender*/, System::EventArgs^ /*e*/
 )
   {
      pictureBox1 = gcnew PictureBox;

      // Dock the PictureBox to the form and set its background to white.
      pictureBox1->Dock = DockStyle::Fill;
      pictureBox1->BackColor = Color::White;

      // Connect the Paint event of the PictureBox to the event handler
 method.
      pictureBox1->Paint += gcnew System::Windows::Forms::PaintEventHandler( this,
 &Form1::pictureBox1_Paint );

      // Add the PictureBox control to the Form.
      this->Controls->Add( pictureBox1 );
   }

   void pictureBox1_Paint( Object^ /*sender*/, System::Windows::Forms::PaintEventArgs^
 e )
   {
      // Create a local version of the graphics object for the PictureBox.
      Graphics^ g = e->Graphics;

      // Draw a string on the PictureBox.
      g->DrawString( "This is a diagonal line drawn on the control"
,
         gcnew System::Drawing::Font( "Arial",10 ), System::Drawing::Brushes::Blue,
 Point(30,30) );

      // Draw a line in the PictureBox.
      g->DrawLine( System::Drawing::Pens::Red, pictureBox1->Left, pictureBox1->Top
,
         pictureBox1->Right, pictureBox1->Bottom );
   }
// This example creates a PictureBox control on the form and draws to
 it.
// This example assumes that the Form_Load event handler method is
// connected to the Load event of the form.
private PictureBox pictureBox1 = new PictureBox();

private void Form1_Load(Object sender, System.EventArgs
 e)
{
    // Dock the PictureBox to the form and set its background to white.
    pictureBox1.set_Dock(DockStyle.Fill);
    pictureBox1.set_BackColor(Color.get_White());

    // Connect the Paint event of the PictureBox to the event handler
 
    // method.
    pictureBox1.add_Paint(new System.Windows.Forms.PaintEventHandler(this.
        pictureBox1_Paint));

    // Add the PictureBox control to the Form.
    this.get_Controls().Add(pictureBox1);
} //Form1_Load

private void pictureBox1_Paint(Object sender,
 
    System.Windows.Forms.PaintEventArgs e)
{
    // Create a local version of the graphics object for the PictureBox.
    Graphics g = e.get_Graphics();

    // Draw a string on the PictureBox.
    g.DrawString("This is a diagonal line drawn on the control", 
        new Font("Arial", 10), System.Drawing.Brushes.get_Blue(),
 
        (PointF)new PointF(30, 30));

    // Draw a line in the PictureBox.
    g.DrawLine(System.Drawing.Pens.get_Red(), pictureBox1.get_Left(), 
        pictureBox1.get_Top(), pictureBox1.get_Right(), 
        pictureBox1.get_Bottom());
} //pictureBox1_Paint
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

ControlPaint クラス

共通の Windows コントロールとその要素を描画するために使用するメソッドを提供します。このクラスは継承できません。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public NotInheritable Class
 ControlPaint
public sealed class ControlPaint
public ref class ControlPaint sealed
public final class ControlPaint
public final class ControlPaint
解説解説
使用例使用例

ControlPaint のコンストラクタの 1 つを使用して、フラットな Button コントロールを描画するコード例を次に示します。

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
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);
    }
}
#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 ref class Form1: public
 Form
{
private:
   Button^ button1;
   Button^ button2;

public:
   Form1()
   {
      button1 = gcnew Button;
      button2 = gcnew Button;
      this->button2->Location = Point(0,button1->Height
 + 10);
      this->Click += gcnew 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( gcnew Form1 );
}

import System.*;
import System.Drawing.*;
import System.Windows.Forms.*;

public class Form1 extends Form
{
    private Button button1 = new Button();
    private Button button2 = new Button();

    /** @attribute STAThread()
     */
    public static void main(String[]
 args)
    {
        Application.Run(new Form1());
    } //main

    public Form1()
    {
        this.button2.set_Location(new Point(0,
 button1.get_Height() + 10));
        this.add_Click(new EventHandler(this.button2_Click));
        this.get_Controls().Add(this.button1);
        this.get_Controls().Add(this.button2);
    } //Form1

    private void button2_Click(Object sender,
 System.EventArgs e)
    {
        // Draws a flat button on button1.
        ControlPaint.DrawButton(System.Drawing.Graphics.FromHwnd(
            button1.get_Handle()), 0, 0, button1.get_Width(), 
            button1.get_Height(), ButtonState.Flat);
    } //button2_Click
} //Form1
継承階層継承階層
System.Object
  System.Windows.Forms.ControlPaint
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

ControlPaint プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ ContrastControlDark ControlDark 色として使用する色を取得します。
参照参照

関連項目

ControlPaint クラス
System.Windows.Forms 名前空間
Control クラス
ControlStyles

ControlPaint メソッド


パブリック メソッドパブリック メソッド

( プロテクト メソッド も参照)
  名前 説明
パブリック メソッド CreateHBitmap16Bit 16 ビットのカラー ビットマップを作成します。
パブリック メソッド CreateHBitmapColorMask イメージから Win32 HBITMAP を作成します。
パブリック メソッド CreateHBitmapTransparencyMask 指定したビットマップの、透明として表示する色を示す色マスクを作成します。
パブリック メソッド Dark オーバーロードされます。 コントロールの新しい濃い色のオブジェクトを作成します。
パブリック メソッド DarkDark 指定した色からコントロールの新しい濃い色のオブジェクトを作成します。
パブリック メソッド DrawBorder オーバーロードされます。 ボタン スタイルのコントロールの輪郭を描画します。
パブリック メソッド DrawBorder3D オーバーロードされます。 コントロールの 3 次元スタイルの輪郭を描画します。
パブリック メソッド DrawButton オーバーロードされます。 ボタン コントロールを描画します。
パブリック メソッド DrawCaptionButton オーバーロードされます。 キャプション ボタン コントロールを描画します。
パブリック メソッド DrawCheckBox オーバーロードされます。 チェック ボックス コントロールを描画します。
パブリック メソッド DrawComboButton オーバーロードされます。 コンボ ボックス コントロールのドロップダウン ボタンを描画します。
パブリック メソッド DrawContainerGrabHandle コンテナ コントロールのグラブ ハンドル グリフを、指定したグラフィックスの表面の指定した範囲内に描画します。
パブリック メソッド DrawFocusRectangle オーバーロードされます。 フォーカスを示す四角形を描画します。
パブリック メソッド DrawGrabHandle 標準の選択項目のグラブ ハンドル グリフを、指定した状態およびスタイルで、指定したグラフィックスの表面の指定した範囲内に描画します。
パブリック メソッド DrawGrid 1 ピクセルの点線で構成されたグリッドを指定した間隔で、指定した色を使用して、指定したグラフィックスの表面の指定した範囲内に描画します。
パブリック メソッド DrawImageDisabled 指定したイメージを無効状態で描画します。
パブリック メソッド DrawLockedFrame 画面に表示されるロックされた選択項目の枠を、指定した範囲内の指定したグラフィックスの表面に描画します。主要な選択項目色を使用して、枠を描画するかどうかを指定します。
パブリック メソッド DrawMenuGlyph オーバーロードされます。 メニュー項目のコントロールのメニュー グリフを描画します。
パブリック メソッド DrawMixedCheckBox オーバーロードされます。 3 ステート チェック ボックス コントロールを描画します。
パブリック メソッド DrawRadioButton オーバーロードされます。 オプション ボタン コントロールを描画します。
パブリック メソッド DrawReversibleFrame 画面の反転できる枠を、指定した範囲内に、指定した背景色を使用して、指定した状態で描画します。
パブリック メソッド DrawReversibleLine 画面の反転できる線を、指定した開始点と指定したエンド ポイントの間に、指定した背景色を使用して描画します。
パブリック メソッド DrawScrollButton オーバーロードされます。 スクロール バー コントロールのスクロール ボタンを描画します。
パブリック メソッド DrawSelectionFrame 標準の選択項目の枠を、指定した状態で、指定したグラフィックスの表面に、指定した内部と外部の大きさで、指定した背景色を使用して描画します。
パブリック メソッド DrawSizeGrip オーバーロードされます。 フォームのサイズ グリップを描画します。
パブリック メソッド DrawStringDisabled オーバーロードされます。 指定した文字列を無効状態で描画します。
パブリック メソッド DrawVisualStyleBorder 無効状態の項目に、適切なスタイルの文字列を描画します。
パブリック メソッド Equals  オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。)
パブリック メソッド FillReversibleRectangle 画面上の塗りつぶされた反転できる四角形を描画します。
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 ( Object から継承されます。)
パブリック メソッド Light オーバーロードされます。 コントロールの新しい明るい色のオブジェクトを作成します。
パブリック メソッド LightLight 指定した色からコントロールの新しい明るい色のオブジェクトを作成します。
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String を返します。 ( Object から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

ControlPaint クラス
System.Windows.Forms 名前空間
Control クラス
ControlStyles

ControlPaint メンバ

共通の Windows コントロールとその要素を描画するために使用するメソッドを提供します。このクラスは継承できません。

ControlPaint データ型で公開されるメンバを以下の表に示します。


パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ ContrastControlDark ControlDark 色として使用する色を取得します。
パブリック メソッドパブリック メソッド
( プロテクト メソッド も参照)
  名前 説明
パブリック メソッド CreateHBitmap16Bit 16 ビットのカラー ビットマップを作成します。
パブリック メソッド CreateHBitmapColorMask イメージから Win32 HBITMAP を作成します。
パブリック メソッド CreateHBitmapTransparencyMask 指定したビットマップの、透明として表示する色を示す色マスクを作成します。
パブリック メソッド Dark オーバーロードされます。 コントロールの新しい濃い色のオブジェクトを作成します。
パブリック メソッド DarkDark 指定した色からコントロールの新しい濃い色のオブジェクトを作成します。
パブリック メソッド DrawBorder オーバーロードされます。 ボタン スタイルのコントロールの輪郭を描画します。
パブリック メソッド DrawBorder3D オーバーロードされます。 コントロールの 3 次元スタイルの輪郭を描画します。
パブリック メソッド DrawButton オーバーロードされます。 ボタン コントロールを描画します。
パブリック メソッド DrawCaptionButton オーバーロードされます。 キャプション ボタン コントロールを描画します。
パブリック メソッド DrawCheckBox オーバーロードされます。 チェック ボックス コントロールを描画します。
パブリック メソッド DrawComboButton オーバーロードされます。 コンボ ボックス コントロールのドロップダウン ボタンを描画します。
パブリック メソッド DrawContainerGrabHandle コンテナ コントロールのグラブ ハンドル グリフを、指定したグラフィックスの表面の指定した範囲内に描画します。
パブリック メソッド DrawFocusRectangle オーバーロードされます。 フォーカスを示す四角形を描画します。
パブリック メソッド DrawGrabHandle 標準の選択項目のグラブ ハンドル グリフを、指定した状態およびスタイルで、指定したグラフィックスの表面の指定した範囲内に描画します。
パブリック メソッド DrawGrid 1 ピクセルの点線で構成されたグリッドを指定した間隔で、指定した色を使用して、指定したグラフィックスの表面の指定した範囲内に描画します。
パブリック メソッド DrawImageDisabled 指定したイメージを無効状態で描画します。
パブリック メソッド DrawLockedFrame 画面に表示されるロックされた選択項目の枠を、指定した範囲内の指定したグラフィックスの表面に描画します。主要な選択項目色を使用して、枠を描画するかどうかを指定します。
パブリック メソッド DrawMenuGlyph オーバーロードされます。 メニュー項目のコントロールのメニュー グリフを描画します。
パブリック メソッド DrawMixedCheckBox オーバーロードされます。 3 ステート チェック ボックス コントロールを描画します。
パブリック メソッド DrawRadioButton オーバーロードされます。 オプション ボタン コントロールを描画します。
パブリック メソッド DrawReversibleFrame 画面の反転できる枠を、指定した範囲内に、指定した背景色を使用して、指定した状態で描画します。
パブリック メソッド DrawReversibleLine 画面の反転できる線を、指定した開始点と指定したエンド ポイントの間に、指定した背景色を使用して描画します。
パブリック メソッド DrawScrollButton オーバーロードされます。 スクロール バー コントロールのスクロール ボタンを描画します。
パブリック メソッド DrawSelectionFrame 標準の選択項目の枠を、指定した状態で、指定したグラフィックスの表面に、指定した内部と外部の大きさで、指定した背景色を使用して描画します。
パブリック メソッド DrawSizeGrip オーバーロードされます。 フォームのサイズ グリップを描画します。
パブリック メソッド DrawStringDisabled オーバーロードされます。 指定した文字列を無効状態で描画します。
パブリック メソッド DrawVisualStyleBorder 無効状態の項目に、適切なスタイルの文字列を描画します。
パブリック メソッド Equals  オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。)
パブリック メソッド FillReversibleRectangle 画面上の塗りつぶされた反転できる四角形を描画します。
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 (Object から継承されます。)
パブリック メソッド Light オーバーロードされます。 コントロールの新しい明るい色のオブジェクトを作成します。
パブリック メソッド LightLight 指定した色からコントロールの新しい明るい色のオブジェクトを作成します。
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String を返します。 (Object から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

ControlPaint クラス
System.Windows.Forms 名前空間
Control クラス
ControlStyles



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「ControlPaint」の関連用語

ControlPaintのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ControlPaintのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS