PaintEventHandler 대리자
Control의 Paint 이벤트를 처리할 메서드를 나타냅니다.
네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)
구문
‘선언
Public Delegate Sub PaintEventHandler ( _
sender As Object, _
e As PaintEventArgs _
)
‘사용 방법
Dim instance As New PaintEventHandler(AddressOf HandlerMethod)
public delegate void PaintEventHandler (
Object sender,
PaintEventArgs e
)
public delegate void PaintEventHandler (
Object^ sender,
PaintEventArgs^ e
)
/** @delegate */
public delegate void PaintEventHandler (
Object sender,
PaintEventArgs e
)
JScript에서는 대리자를 사용할 수 있지만 새로 선언할 수는 없습니다.
매개 변수
- sender
이벤트 소스입니다.
- e
이벤트 데이터가 들어 있는 PaintEventArgs입니다.
설명
PaintEventHandler 대리자를 만드는 경우 이벤트를 처리할 메서드를 결정합니다. 이벤트를 이벤트 처리기와 연결하려면 대리자의 인스턴스를 해당 이벤트에 추가합니다. 대리자를 제거하지 않는 경우 이벤트가 발생할 때마다 이벤트 처리기가 호출됩니다. 대리자로 이벤트를 처리하는 방법에 대한 자세한 내용은 이벤트 및 대리자를 참조하십시오.
예제
' 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에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.
버전 정보
.NET Framework
2.0, 1.1, 1.0에서 지원
.NET Compact Framework
2.0, 1.0에서 지원
참고 항목
참조
System.Windows.Forms 네임스페이스
OnPaint
Control.Paint 이벤트
PaintEventArgs 클래스