Control.Paint イベント
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

public: event PaintEventHandler^ Paint { void add (PaintEventHandler^ value); void remove (PaintEventHandler^ value); }


フォーム上で 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

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


ControlPaint クラス
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)


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

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.Windows.Forms.ControlPaint


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


ControlPaint プロパティ
ControlPaint メソッド


名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

ControlPaint メンバ
共通の Windows コントロールとその要素を描画するために使用するメソッドを提供します。このクラスは継承できません。
ControlPaint データ型で公開されるメンバを以下の表に示します。



名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

Weblioに収録されているすべての辞書からControl.Paintを検索する場合は、下記のリンクをクリックしてください。

- Control.Paintのページへのリンク