|
■No65079 (もとみ さん) に返信
VB.NET版ですがこんな感じでどうでしょう? いろんな変数の後始末とかしていないので参考程度にしてください。
Public Class Form1 Private gp As Graphics Private pt1 As Point Private stopflg As Boolean = True Private drawflg As Boolean = False Private starttime As Date
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load gp = PictureBox1.CreateGraphics() End Sub
Private Sub PictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove If stopflg Then pt1 = e.Location stopflg = False starttime = Date.Now() Else Dim nowtime = Date.Now() If nowtime.Subtract(starttime).TotalMilliseconds < 10 Then Exit Sub Dim pt2 = e.Location Dim dest = Math.Sqrt((pt2.X - pt1.X) ^ 2 + (pt2.Y - pt1.Y) ^ 2) If drawflg Then gp.DrawLine(Pens.Black, pt1, pt2) End If pt1 = pt2 If dest > 5 Then Timer1.Stop() Else Timer1.Interval = 2000 Timer1.Start() End If End If End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick Timer1.Stop() drawflg = Not drawflg If drawflg Then PictureBox1.Cursor = Cursors.Cross Else PictureBox1.Cursor = Cursors.Default End If End Sub End Class
|