Evento Shape.Paint
Si verifica quando la forma viene ridisegnata.
Spazio dei nomi: Microsoft.VisualBasic.PowerPacks
Assembly: Microsoft.VisualBasic.PowerPacks.Vs (in Microsoft.VisualBasic.PowerPacks.Vs.dll)
Sintassi
'Dichiarazione
<BrowsableAttribute(True)> _
Public Event Paint As PaintEventHandler
[BrowsableAttribute(true)]
public event PaintEventHandler Paint
[BrowsableAttribute(true)]
public:
event PaintEventHandler^ Paint {
void add (PaintEventHandler^ value);
void remove (PaintEventHandler^ value);
}
[<BrowsableAttribute(true)>]
member Paint : IEvent<PaintEventHandler,
PaintEventArgs>
JScript non supporta gli eventi.
Note
Il Paint gestore eventi viene in genere utilizzato per eseguire il disegno personalizzato quando viene ridisegnata una forma.
Per ulteriori informazioni su come gestire gli eventi, vedere Gestione e generazione di eventi.
Esempi
Nell'esempio seguente viene illustrato come utilizzare il Paint evento per disegnare linee in un RectangleShape controllo. Si suppone di disporre di un RectangleShape controllo denominato RectangleShape1 in un form.
Private mousePath = New System.Drawing.Drawing2D.GraphicsPath()
Private Sub RectangleShape2_MouseDown(
ByVal sender As Object,
ByVal e As System.Windows.Forms.MouseEventArgs
) Handles RectangleShape2.MouseDown
Dim mouseDownLocation As New Point(e.X + RectangleShape2.Left,
e.Y + RectangleShape2.Top)
' Clear the previous line.
mousePath.Dispose()
mousePath = New System.Drawing.Drawing2D.GraphicsPath()
RectangleShape2.Invalidate()
' Add a line to the graphics path.
mousePath.AddLine(mouseDownLocation, mouseDownLocation)
End Sub
Private Sub RectangleShape2_MouseMove(
ByVal sender As Object,
ByVal e As System.Windows.Forms.MouseEventArgs
) Handles RectangleShape2.MouseMove
Dim mouseX As Integer = e.X + RectangleShape2.Left
Dim mouseY As Integer = e.Y + RectangleShape2.Top
' Add a line to the graphics path.
mousePath.AddLine(mouseX, mouseY, mouseX, mouseY)
End Sub
Private Sub RectangleShape2_MouseUp(
ByVal sender As Object,
ByVal e As System.Windows.Forms.MouseEventArgs
) Handles RectangleShape2.MouseUp
Dim mouseUpLocation = New System.Drawing.Point(e.X +
RectangleShape2.Left, e.Y + RectangleShape2.Top)
' Add a line to the graphics path.
mousePath.Addline(mouseUpLocation, mouseUpLocation)
' Force the shape to redraw.
RectangleShape2.Invalidate()
End Sub
Private Sub RectangleShape2_Paint(
ByVal sender As Object,
ByVal e As System.Windows.Forms.PaintEventArgs
) Handles RectangleShape2.Paint
' Draw the line.
e.Graphics.DrawPath(System.Drawing.Pens.DarkRed, mousePath)
End Sub
private System.Drawing.Drawing2D.GraphicsPath mousePath =
new System.Drawing.Drawing2D.GraphicsPath();
private void rectangleShape2_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
Point mouseDownLocation = new Point(e.X + rectangleShape2.Left,
e.Y + rectangleShape2.Top);
// Clear the previous line.
mousePath.Dispose();
mousePath = new System.Drawing.Drawing2D.GraphicsPath();
rectangleShape2.Invalidate();
// Add a line to the graphics path.
mousePath.AddLine(mouseDownLocation, mouseDownLocation);
}
private void rectangleShape2_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e)
{
int mouseX = e.X + rectangleShape2.Left;
int mouseY = e.Y + rectangleShape2.Top;
// Add a line to the graphics path.
mousePath.AddLine(mouseX, mouseY, mouseX, mouseY);
}
private void rectangleShape2_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
System.Drawing.Point mouseUpLocation =
new System.Drawing.Point(e.X + rectangleShape2.Left,
e.Y + rectangleShape2.Top);
// Add a line to the graphics path.
mousePath.AddLine(mouseUpLocation, mouseUpLocation);
// Force the shape to redraw.
rectangleShape2.Invalidate();
}
private void rectangleShape2_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
// Draw the line.
e.Graphics.DrawPath(System.Drawing.Pens.DarkRed, mousePath);
}
Sicurezza di .NET Framework
- Attendibilità totale per il chiamante immediato. Impossibile utilizzare questo membro in codice parzialmente attendibile. Per altre informazioni, vedere Utilizzo di librerie da codice parzialmente attendibile.
Vedere anche
Riferimenti
Spazio dei nomi Microsoft.VisualBasic.PowerPacks
Altre risorse
Procedura: disegnare linee con il controllo LineShape (Visual Studio)
Procedura: disegnare forme con i controlli OvalShape e RectangleShape (Visual Studio)