在vb.net中移动图片框上的点

时间:2015-04-25 15:43:12

标签: vb.net image overlay picturebox

我有一个图片框,需要在给定的坐标处绘制一个红色像素。此像素将移动,当我指定新位置时,旧位置将被移除,因此在任何给定时间只有一个像素为红色。 如果可能的话,这个像素透明度为50%会很好。

最关键的是它必须快速。它仅用于显示在图像上处理的当前位置,因此必须不会减慢主程序的速度。

可以这样做吗? 感谢

1 个答案:

答案 0 :(得分:1)

除了汉斯的评论:

Dim currentPoint As Point = Point.Empty 
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
    ' Clear previous pixel
    Dim invalidRect As Rectangle = New Rectangle(currentPoInteger.X,currentPoInteger.Y, 1, 1) 
    pictureBox1.Invalidate(invalidRect)

    ' Move to next point some how
    currentPoint.X = currentPoint.X + 1

    ' Invalidate to draw new pixel
    invalidRect = New Rectangle(currentPoInteger.X, currentPoInteger.Y, 1, 1)
    pictureBox1.Invalidate(invalidRect)
End Sub

Private  Sub pictureBox1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles pictureBox1.Click
    If e.ClipRectangle.Contains(currentPoint) Then
        e.Graphics.FillRectangle(Brushes.Red, currentPoInteger.X, currentPoInteger.Y, 1, 1)
    End If
End Sub