Public Class Form1 Private PreviousPoint As Point ' Dernier point de la souris Private ThePen As New System.Drawing.Pen(Color.Black, 10) 'Un Pen pour dessiner. Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load PictureBox1.Location = New Point(20, 20) PictureBox1.Size = New Size(200, 200) PictureBox2.Location = New Point(50, 50) PictureBox2.Size = New Size(100, 100) PictureBox2.BackColor = Color.Transparent PictureBox2.BorderStyle = BorderStyle.FixedSingle PictureBox1.BackColor = Color.Ivory PictureBox1.Controls.Add(PictureBox2) End Sub 'efface Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click ThePen.Color = Color.Ivory End Sub 'dessine Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click ThePen.Color = Color.Black End Sub Private Sub PictureBox1_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove If PictureBox1.Capture Then Dim NewPoint As New Point(e.X, e.Y) Dim NewGraphic As Graphics = PictureBox1.CreateGraphics() NewGraphic.DrawLine(ThePen, PreviousPoint, NewPoint) NewGraphic.Dispose() PreviousPoint = NewPoint End If End Sub Private Sub PictureBox2_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PictureBox2.MouseMove If PictureBox2.Capture Then Dim NewPoint As New Point(e.X, e.Y) Dim NewGraphic As Graphics = PictureBox2.CreateGraphics() NewGraphic.DrawLine(ThePen, PreviousPoint, NewPoint) NewGraphic.Dispose() PreviousPoint = NewPoint End If End Sub End Class
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question