1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| Private _g As System.Drawing.Graphics
Private monStylo As New System.Drawing.Pen(System.Drawing.Color.Red)
Private _mouseDown As Boolean
Private Xo, Yo, Xf, Yf As Integer
Sub New()
InitializeComponent()
_g = pbDroite.CreateGraphics()
_g.SmoothingMode = Drawing2D.SmoothingMode.HighSpeed
End Sub
Private Sub pbDroite_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pbDroite.MouseDown
Xo = e.X
Yo = e.Y
_mouseDown = True
Cursor = Cursors.Cross
End Sub
Private Sub pbDroite_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pbDroite.MouseMove
If _mouseDown Then
Xf = e.X
Yf = e.Y
pbDroite.Refresh()
_g.DrawRectangle(monStylo, New Rectangle(Xo, Yo, Xf - Xo, Yf - Yo))
End If
End Sub
Private Sub pbDroite_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pbDroite.MouseUp
_mouseDown = False
Cursor = Cursors.Arrow
End Sub |