Private?Sub?Form_Load()
Line1.Visible?=?False
End?Sub
Private?Sub?Form_MouseDown(Button?As?Integer,?Shift?As?Integer,?X?As?Single,?Y?As?Single)
If?Button?=?1?Then
x1?=?X
y1?=?Y
End?If
End?Sub
Private?Sub?Form_MouseMove(Button?As?Integer,?Shift?As?Integer,?X?As?Single,?Y?As?Single)
If?Button?=?1?Then
Line1.x1?=?x1
Line1.y1?=?y1
Line1.x2?=?X
Line1.y2?=?Y
Line1.Visible?=?True
End?If
End?Sub
Private?Sub?Form_MouseUp(Button?As?Integer,?Shift?As?Integer,?X?As?Single,?Y?As?Single)
If?Button?=?1?Then
Line1.Visible?=?False
x2?=?X
y2?=?Y
If?m?=?0?Then
m?=?Me.ScaleX(Sqr((x2?-?x1)?^?2?+?(y2?-?y1)?^?2),?1,?3)
MsgBox?"標尺的像素長度m="?&?m
ElseIf?n?=?0?Then
n?=?Me.ScaleX(Sqr((x2?-?x1)?^?2?+?(y2?-?y1)?^?2),?1,?3)
L?=?5?*?n?/?m
MsgBox?"兩點之間的像素長度n="?&?n?&?vbCrLf?&?"兩點之間的標尺距離L="?&?L?&?"mm"
m?=?0
n?=?0
L?=?0
End?If
End?If
End?Sub
上述代碼用到的唯壹壹個控件是Line1