简体   繁体   English

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

[英]Moving dot on picturebox in vb.net

I have a picturebox, and would need to draw a single red pixel at a given coordinate. 我有一个图片框,需要在给定坐标处绘制一个红色像素。 This pixel will move, and when i assign a new position the old position is removed, so that only a single pixel is red at any given time. 该像素将移动,并且当我分配新位置时,旧位置将被删除,因此在任何给定时间只有一个像素为红色。 If possible it would be nice that this pixel is 50% transparent. 如果可能的话,此像素为50%透明会很好。

The most crucial thing is that it has to be fast. 最关键的是它必须快速。 It is just used to display the current position that is beeing processed on the image, so it is imperative that it does not slow down the main program. 它仅用于显示图像上正在处理的当前位置,因此必须确保它不会减慢主程序的速度。

Can this be done? 能做到吗? Thanks 谢谢

In addition to Hans's comment: 除了汉斯的评论:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM