main.frm
来自「很好的教程原代码!」· FRM 代码 · 共 57 行
FRM
57 行
VERSION 5.00
Begin VB.Form Main
Caption = "用鼠标点选直线"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
End
Attribute VB_Name = "Main"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub Command1_Click()
LineDDA 100, 100, 105, 105, AddressOf LineDDAProc, 0
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim i As Integer, selected As Boolean
' 判断第一条线
nPoints = 0
LineDDA 20, 20, 200, 200, AddressOf LineDDAProc, 0
For i = 0 To nPoints - 1
If ((pX(i) - X) ^ 2 + (pY(i) - Y) ^ 2) ^ 0.5 < 3 Then
MsgBox "您点选的是 (20, 20) - (200, 200) 线段!"
selected = True
Exit For
End If
Next
' 判断第二条线
nPoints = 0
LineDDA 20, 150, 200, 50, AddressOf LineDDAProc, 0
For i = 0 To nPoints - 1
If ((pX(i) - X) ^ 2 + (pY(i) - Y) ^ 2) ^ 0.5 < 3 Then
MsgBox "您点选的是 (20, 150) - (200, 50) 线段!"
selected = True
Exit For
End If
Next
If Not selected Then
MsgBox "您没有点选到任何线段!"
End If
End Sub
Private Sub Form_Paint()
Me.ScaleMode = vbPixels
Line (20, 20)-(200, 200)
Line (20, 150)-(200, 50)
End Sub
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?