在 vb.net 中移动图片框上的点
Moving dot on picturebox in vb.net
我有一个图片框,需要在给定坐标处绘制一个红色像素。这个像素会移动,当我分配一个新位置时旧位置被删除,所以在任何给定时间只有一个像素是红色的。
如果可能的话,这个像素是 50% 透明的就好了。
最关键的是要快。它只是用来显示图像上正在处理的当前位置,因此必须不拖慢主程序。
这能做到吗?
谢谢
除了汉斯的评论:
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
我有一个图片框,需要在给定坐标处绘制一个红色像素。这个像素会移动,当我分配一个新位置时旧位置被删除,所以在任何给定时间只有一个像素是红色的。 如果可能的话,这个像素是 50% 透明的就好了。
最关键的是要快。它只是用来显示图像上正在处理的当前位置,因此必须不拖慢主程序。
这能做到吗? 谢谢
除了汉斯的评论:
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