Exercice Visual Basic : Mini Pint

Ecrire le code qui permet de réalser l'interface suivante:
NB: Le principe c'est de réaliser un Mini Pint
ExerciceVB-id2106


 

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
Public Class Form1
    Dim P As New Pen(Color.Black), AvPoint As Point, PrecColor As Color
    Dim Graf, g As Graphics, Bitmap_ As Bitmap
 
    Private Sub FermerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
 
    End Sub
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Bitmap_ = New Bitmap(Me.PictureBox1.Width, Me.PictureBox1.Height)
    End Sub
 
    Private Sub PictureBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
        Dim NewPoint As New Point(e.X, e.Y)
        AvPoint = NewPoint
    End Sub
 
    Private Sub PictureBox1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
        Dim p_ As New Point(e.X, e.Y)
        If (Me.PictureBox1.Capture) Then
            Graf = Me.PictureBox1.CreateGraphics
            g = Graphics.FromImage(Bitmap_)
            Graf.DrawLine(P, p_, AvPoint)
            g.DrawLine(P, p_, AvPoint)
            AvPoint = p_
        End If
 
    End Sub
 
    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.ColorDialog1.ShowDialog()
        Me.P.Color = Me.ColorDialog1.Color
    End Sub
 
    Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click
        Me.PictureBox1.Image = Bitmap_
        Me.SaveFileDialog1.Title = "Enregistrer l'image"
        Me.SaveFileDialog1.Filter = "image(*.png)|*.png"
        Me.SaveFileDialog1.ShowDialog()
        Try
            Me.PictureBox1.Image.Save(Me.SaveFileDialog1.FileName)
        Catch ex As Exception
            MsgBox("Erreur :" + Err.Description, MsgBoxStyle.Critical)
        End Try
 
    End Sub
 
    Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
        Me.PrecColor = P.Color
        Me.Cursor = Cursors.No
        Me.P.Color = Color.White
        P.Width = 10
    End Sub
 
    Private Sub ToolStripButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton4.Click
        Me.Cursor = Cursors.Default
        P.Width = 1
        P.Color = Me.PrecColor
    End Sub
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ChangeC(Me.Button1)
    End Sub
 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ChangeC(Me.Button2)
    End Sub
    Private Sub ChangeC(ByVal b As Button)
        Me.PictureBox2.BackColor = b.BackColor
        P.Color = b.BackColor
    End Sub
 
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        ChangeC(Me.Button4)
    End Sub
 
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        ChangeC(Me.Button3)
    End Sub
 
    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        ChangeC(Me.Button6)
    End Sub
 
    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        ChangeC(Me.Button5)
    End Sub
 
    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        ChangeC(Me.Button8)
    End Sub
 
    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        ChangeC(Me.Button7)
    End Sub
 
    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        ChangeC(Me.Button10)
    End Sub
 
    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        ChangeC(Me.Button9)
    End Sub
 
    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
        ChangeC(Me.Button12)
    End Sub
 
    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        ChangeC(Me.Button11)
    End Sub
 
    Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
        ChangeC(Me.Button14)
    End Sub
 
    Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
        ChangeC(Me.Button13)
    End Sub
 
    Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
        ChangeC(Me.Button16)
    End Sub
 
    Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
        ChangeC(Me.Button15)
    End Sub
 
    Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click
        ChangeC(Me.Button18)
    End Sub
 
    Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
        ChangeC(Me.Button17)
    End Sub
 
    Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.Click
        ChangeC(Me.Button20)
    End Sub
 
    Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button19.Click
        ChangeC(Me.Button19)
    End Sub
 
    Private Sub ImageToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ImageToolStripMenuItem.Click
        Me.OpenFileDialog1.Filter = "*.png|(*.png)|*.jpeg|(*.jpeg)|*.jpg|(*.jpg)|*.bmp|(*.bmp)"
        Me.OpenFileDialog1.ShowDialog()
        g = Graphics.FromImage(Bitmap_)
        Try
            Me.PictureBox1.Image = New Bitmap(Me.OpenFileDialog1.FileName)
            g.DrawImage(Me.PictureBox1.Image, AvPoint)
        Catch ex As Exception
            MsgBox("Erreur :" + Err.Description, MsgBoxStyle.Critical)
        End Try
 
    End Sub
End Class