画矩形的话,就改成这样:
Option Explicit
'显式声明模块中的所有变量
Dim mx As Single, my As Single, flag As Integer
'mx,my为线段的起点位置(x,y)
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
mx = X
my = Y
flag = 1
Form1.MousePointer = 2
'定义鼠标指针为十字型指针
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If flag = 1 Then
Form1.Cls
Line (mx, my)-(X, Y), , B
'X,Y为线段的移动光标位置(X,Y)
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.AutoRedraw = True
flag = 0
Line (mx, my)-(X, Y), , B
Set Me.Picture = Me.Image
Form1.MousePointer = 0
Me.AutoRedraw = False
End Sub
这样:
Option Explicit
'显式声明模块中的所有变量
Dim mx As Single, my As Single, flag As Integer
'mx,my为线段的起点位置(x,y)
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
mx = X
my = Y
flag = 1
Form1.MousePointer = 2
'定义鼠标指针为十字型指针
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If flag = 1 Then
Form1.Cls
Line (mx, my)-(X, Y)
'X,Y为线段的移动光标位置(X,Y)
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.AutoRedraw = True
flag = 0
Line (mx, my)-(X, Y)
Set Me.Picture = Me.Image
Form1.MousePointer = 0
Me.AutoRedraw = False
End Sub
Dim XStart As Single, YStart As Single
Dim XOld As Single, YOld As Single
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button <> 1 Then Exit Sub
XOld = XStart
XOld = YStart
XStart = X
YStart = Y
DrawMode = 7
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button <> 1 Then Exit Sub
Line (XStart, YStart)-(XOld, YOld)
Line (XStart, YStart)-(X, Y)
XOld = X
YOld = Y
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button <> 1 Then Exit Sub
DrawMode = 13
Line (XStart, YStart)-(XOld, YOld)
Line (XStart, YStart)-(X, Y)
End Sub