在窗體上加入控制元件line1,然後複製下面程式碼,執行後在窗體上拖放滑鼠即可。
OptionExplicit
PrivateSubForm_Load()
Me.AutoRedraw=True
Line1.Visible=False
EndSub
PrivateSubForm_MouseDown(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
WithLine1
.X1=X
.Y1=Y
.X2=X
.Y2=Y
.Visible=True
EndWith
PrivateSubForm_MouseMove(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
IfButton=1Then
EndIf
PrivateSubForm_MouseUp(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
.Visible=False
Line(.X1,.Y1)-(.X2,.Y2)
在窗體上加入控制元件line1,然後複製下面程式碼,執行後在窗體上拖放滑鼠即可。
OptionExplicit
PrivateSubForm_Load()
Me.AutoRedraw=True
Line1.Visible=False
EndSub
PrivateSubForm_MouseDown(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
WithLine1
.X1=X
.Y1=Y
.X2=X
.Y2=Y
.Visible=True
EndWith
EndSub
PrivateSubForm_MouseMove(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
WithLine1
IfButton=1Then
.X2=X
.Y2=Y
EndIf
EndWith
EndSub
PrivateSubForm_MouseUp(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
WithLine1
IfButton=1Then
.Visible=False
Line(.X1,.Y1)-(.X2,.Y2)
EndIf
EndWith
EndSub