Control.Paint 이벤트
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
컨트롤을 다시 그리면 발생합니다.
public:
event System::Windows::Forms::PaintEventHandler ^ Paint;
public event System.Windows.Forms.PaintEventHandler Paint;
public event System.Windows.Forms.PaintEventHandler? Paint;
member this.Paint : System.Windows.Forms.PaintEventHandler
Public Custom Event Paint As PaintEventHandler
이벤트 유형
예제
다음 코드 예제에서는 폼에 컨트롤을 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:
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();
// Cache font instead of recreating font objects each time we paint.
private Font fnt = new Font("Arial",10);
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",
fnt, 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 pictureBox1 As New PictureBox()
Private fnt as New Font("Arial", 10)
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
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", _
fnt, 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
설명
컨트롤 Paint 이 다시 그려지면 이벤트가 발생합니다. 이벤트를 처리하는 메서드에 의 PaintEventArgs instance 전달합니다Paint.
새 사용자 지정 컨트롤 또는 다른 시각적 모양으로 상속된 컨트롤을 만들 때 메서드를 재정의하여 컨트롤을 렌더링하는 OnPaint 코드를 제공해야 합니다. 자세한 내용은 OnPaint 메서드 재정의 및 사용자 지정 컨트롤 그리기 및 렌더링을 참조하세요.
이벤트 처리에 대한 자세한 내용은 이벤트 처리 및 발생 을 참조하십시오.
적용 대상
추가 정보
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET