我先把 小画笔 清除 和 存档的功能写出来
复制程式
Public Class Form1
Dim p As Point
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
p = e.Location
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PictureBox1.Image = New Bitmap(PictureBox1.Size.Width, PictureBox1.Size.Height)
End Sub
'(最普通的笔)
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
If e.Button = Windows.Forms.MouseButtons.Left Then
Dim newGraphics As Graphics = Graphics.FromImage(PictureBox1.Image)
newGraphics.DrawLine(Pens.Black, p, e.Location)
p = e.Location
newGraphics.Dispose()
PictureBox1.Refresh()
End If
End Sub
'(清除钮)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim newGraphics As Graphics = Graphics.FromImage(Me.PictureBox1.Image)
newGraphics.Clear(Me.PictureBox1.BackColor)
newGraphics.Dispose()
PictureBox1.Refresh()
End Sub
'(存档钮)
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
PictureBox1.Image.Save("C:\ABC.bmp")
End Sub
End Class