Remarque
L’accès à cette page nécessite une autorisation. Vous pouvez essayer de vous connecter ou de modifier des répertoires.
L’accès à cette page nécessite une autorisation. Vous pouvez essayer de modifier des répertoires.
Mise à jour : novembre 2007
Se produit lorsque le pointeur de la souris se trouve sur la forme et qu'un bouton de la souris est enfoncé.
Espace de noms : Microsoft.VisualBasic.PowerPacks
Assembly : Microsoft.VisualBasic.PowerPacks.Vs (dans Microsoft.VisualBasic.PowerPacks.Vs.dll)
Syntaxe
<BrowsableAttribute(True)> _
Public Event MouseDown As MouseEventHandler
Dim instance As Shape
Dim handler As MouseEventHandler
AddHandler instance.MouseDown, handler
[BrowsableAttribute(true)]
public event MouseEventHandler MouseDown
[BrowsableAttribute(true)]
public:
event MouseEventHandler^ MouseDown {
void add (MouseEventHandler^ value);
void remove (MouseEventHandler^ value);
}
JScript ne prend pas en charge les événements.
Notes
Les événements de souris se produisent dans l'ordre suivant :
MouseHover / MouseDown / MouseWheel
Pour plus d'informations sur la gestion d'événements, consultez Consommation d'événements.
Exemples
L'exemple suivant montre comment utiliser les événements MouseDown, MouseMove et MouseUp pour dessiner des lignes dans un contrôle RectangleShape. Cet exemple suppose qu'il existe un contrôle RectangleShape nommé RectangleShape2 sur un formulaire.
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);
}
Autorisations
- Confiance totale accordée à l'appelant immédiat. Ce membre ne peut pas être utilisé par du code d'un niveau de confiance partiel. Pour plus d'informations, consultez Utilisation de bibliothèques à partir de code d'un niveau de confiance partiel.
Voir aussi
Référence
Microsoft.VisualBasic.PowerPacks, espace de noms
Autres ressources
Comment : dessiner des lignes avec le contrôle LineShape (Visual Studio)
Comment : dessiner des formes avec les contrôles OvalShape et RectangleShape (Visual Studio)