在光标位置Visual Basic绘制图像

时间:2014-11-25 03:49:16

标签: vb.net draw paint cursor-position

基本上我想做的就是在表格或图片框上的位置画一个图像,鼠标点击1秒钟。我尝试过的代码已经在随机偏移中得出它,所以我希望有人可以指导我。谢谢

1 个答案:

答案 0 :(得分:0)

使用Form的MouseDown()事件并在" e.X"指定的位置绘制。和" e.Y"。您可以使用Timer()控件获得一秒钟的延迟。这是一个简单的例子:

Public Class Form1

    Private WithEvents Tmr As New System.Windows.Forms.Timer

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Tmr.Interval = 1000
        Tmr.Enabled = False
    End Sub

    Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles MyBase.MouseDown
        Using G As Graphics = Me.CreateGraphics
            'G.DrawImage(yourImageReferenceHere, New Point(e.X, e.Y))
            Dim rc As New Rectangle(New Point(e.X, e.Y), New Size(1, 1))
            rc.Inflate(9, 9)
            G.DrawEllipse(Pens.Red, rc)
        End Using
        Tmr.Stop()
        Tmr.Start()
    End Sub

    Private Sub Tmr_Tick(sender As Object, e As EventArgs) Handles Tmr.Tick
        Tmr.Stop()
        Me.Refresh()
    End Sub

End Class