Option Explicit
Dim KZD(0 To 10) As xydxy_type
Dim BDMG As Integer
Dim dqtx As Integer
'MouseDown 定心
'MouseMove 定形
'MouseUp 画图
'利用line和shape控件,在vb6.0下,实现几何画板的设计原理。
'补充
'通过鼠标右键移动来实现控点的移动
'根据控点位置决定显示图形大小形状
Private Sub Form_Load()
Dim i As Integer
Shape0(0).Width = 150
Shape0(0).Height = 150
Shape0(0).FillStyle = 0
For i = 1 To 5 '加载控件几何图形 line0通过复制粘贴操作设置为控件数组
Load Line0(i)
Load Shape0(i)
Shape0(i).Width = 150
Shape0(i).Height = 150
Shape0(i).FillStyle = 0
Next i
For i = 1 To 2
KZD(i).xx = KZD(0).xx + KZD(i).dx
KZD(i).yy = KZD(0).yy + KZD(i).dy
Next i
End If
Call shoutx(dqtx)
End Sub
Private Sub Picturego_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim i As Integer
If Button = 2 Then '右键是移动控点功能
Exit Sub
End If
KZD(0).xx = x
KZD(0).yy = y
For i = 1 To 2 '实现整体移动,相对位置不动
KZD(i).xx = KZD(0).xx + KZD(i).dx
KZD(i).yy = KZD(0).yy + KZD(i).dy
Next i
Call shoutx(dqtx)
End Sub
Sub set_daxiao(ByVal MOVx As Integer, ByVal MOVy As Integer, ByVal dq As Integer)
Dim i, mv As Integer '设置形状大小 几何图形 通过鼠标右键移动来实现
Dim dx, dy, ddd, ddd2, ddb, bl As Double
Dim x, y As Integer
'功能 通过鼠标右键移动来实现控点的移动
ddb = 50000 '判断是那个控点近鼠标 三角形等有用
mv = 1
For i = 1 To 2
x = KZD(i).xx
y = KZD(i).yy
dx = Abs(MOVx - x)
dy = Abs(MOVy - y)
ddd = Sqr(dx * dx + dy * dy)
If ddd < ddb Then
mv = i
ddb = ddd
End If
Next i
If dq = 0 Then
x = KZD(0).xx '用勾股定理计算距离
y = KZD(0).yy
dx = Abs(MOVx - x)
dy = Abs(MOVy - y)
ddd = Sqr(dx * dx + dy * dy)
KZD(1).dx = ddd '实际只有一个控点有效,对称的么
KZD(1).dy = 0
KZD(2).dx = 0
KZD(2).dy = ddd
For i = 1 To 2
KZD(i).xx = KZD(0).xx + KZD(i).dx
KZD(i).yy = KZD(0).yy + KZD(i).dy
Next i
ElseIf dq = 1 Then
dx = MOVx - KZD(0).xx
dy = MOVy - KZD(0).yy
KZD(mv).xx = KZD(0).xx + dx '一次只有一个控点位置变化
KZD(mv).yy = KZD(0).yy + dy
KZD(mv).dx = dx
KZD(mv).dy = dy
End If
Call shoutx(dq)
End Sub
Private Sub Picturego_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
'实现目的 设置形状大小 通过鼠标右键移动来实现
If Button = 2 Then
Call set_daxiao(x, y, dqtx)
End If
End Sub
Private Sub Command1_Click() '画图
Dim x, y, x1, y1, x2, y2, rr As Integer
Picturego.DrawWidth = 4
If dqtx = 0 Then '圆
x = KZD(0).xx
y = KZD(0).yy
rr = Abs(KZD(1).xx - KZD(0).xx)
Picturego.Circle (x, y), rr, RGB(0, 0, 0)
Picturego.Circle (x, y), 30, vbRed