我已经编写了以下代码,但是有一个我不想弄清楚的问题。我试图在鼠标单击时在我的图片框中的图像上画一条简单的线。但是,调用了paint方法但没有绘制它,而是在我滚动图片框中的图片时绘制了该点的线..请帮助
Private Sub picCurrentimage_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picCurrentimage.MouseDown
px = e.X
py = e.Y
highlightPic(px, py)
End Sub
Private Sub highlightPic(ByVal x1 As Integer, ByVal y1 As Integer)
haspoint = True
picCurrentimage.Invalidate()
picCurrentimage.Update()
End Sub
Private Sub picCurrentimage_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles picCurrentimage.Paint
If haspoint Then
Dim g As Graphics = picCurrentimage.CreateGraphics
Dim r As Rectangle = New Rectangle(px, py, 600, 10)
Dim pen As Pen = New Pen(Color.FromArgb(128, 32, 100, 200), 1)
Dim b As Brush = New SolidBrush(pen.Color)
g.FillRectangle(b, r)
End If
End Sub