2014-11-25 53 views
0

基本上我想要做的就是在窗體上或鼠標點擊一個圖片框上的位置繪製一個特定的圖像1秒鐘。我已經試過的代碼已經將它繪製成隨機偏移量,所以我希望有人能夠指導我。謝謝在光標位置繪製圖像Visual Basic

回答

0

使用窗體的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