當前位置:編程學習大全網 - 編程軟體 - VB 實現測量窗體上兩點之間的距離

VB 實現測量窗體上兩點之間的距離

Dim?x1?As?Single,?y1?As?Single,?x2?As?Single,?y2?As?Single,?m?As?Single,?n?As?Single,?L?As?Single

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

  • 上一篇:如何打開?Android手機上的JXCF文件
  • 下一篇:web設計簡單的計算機如何讓百分號顯示
  • copyright 2024編程學習大全網