02/10/2018, 00:05
Viết chương trình MS paint đơn giản.
Hôm nay, mình xin hướng dẫn các bạn viết một chương trình ms paint đơn giản, ở đây ta cần 1 picturebox, (panel để vẽ hình lên) và các button dùng để thay đổi màu sắc, - Ở đây chúng ta dùng sự kiện mouse move để vẽ là chính. Code tham khảo ở dưới ...
Hôm nay, mình xin hướng dẫn các bạn viết một chương trình ms paint đơn giản, ở đây ta cần 1 picturebox, (panel để vẽ hình lên) và các button dùng để thay đổi màu sắc,

- Ở đây chúng ta dùng sự kiện mouse move để vẽ là chính.
Code tham khảo ở dưới đây:
Dim down = False
Dim mybrush = Brushes.Black
Private Sub PictureBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseDown
down = True
End Sub
Private Sub PictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove
If down = True Then
PictureBox1.CreateGraphics.FillEllipse(mybrush, e.X, e.Y, 15, 15)
End If
End Sub
Private Sub PictureBox1_MouseUp(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseUp
down = False
End Sub
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
mybrush = Brushes.Yellow
End Sub
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
mybrush = Brushes.Red
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
mybrush = Brushes.Blue
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
mybrush = Brushes.Green
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
mybrush = Brushes.Purple
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
mybrush = Brushes.Pink
End Sub
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
mybrush = Brushes.Brown
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
mybrush = Brushes.Orange
End Sub
Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
mybrush = Brushes.Black
End Sub
Chúc các bạn thành công!