2015-04-25 48 views
0

我有一个图片框,需要在给定的坐标上画一个红色像素。这个像素会移动,当我分配一个新的位置时,旧的位置将被移除,这样在任何给定的时间只有一个像素是红色的。 如果可能的话,这个像素是50%透明会很好。在vb.net的图片框上移动点

最关键的是它必须快速。它只是用来显示图像上正在处理的当前位置,所以它不能减慢主程序的速度。

可以这样做吗? 感谢

+0

使用Paint事件来绘制点。当你移动它然后调用Invalidate()强制重绘。请记住,您可能必须注意SizeMode属性以确定在哪里绘制点,只有在使用SizeMode = Normal时才很容易。 –

回答

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