2015-04-25 53 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