VB求助!!!我全部的分来换正解!!!

来源:百度知道 编辑:UC知道 时间:2024/05/26 19:46:07
Dim x1 As Single, x2 As Single, y1 As Single, y2 As Single
Private Sub form_load()
Picture1.FillStyle = 0
Picture1.FillColor = vbRed
End Sub

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
x1 = X
y1 = Y
ElseIf Button = 2 Then
Picture1.Cls
End If
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'If Button = 1 Then
'x2 = X
'y2 = Y
'r = Sqr((x1 - x2) ^ 2 + (y1 - y2) ^ 2)
'Picture1.Circle (x1, y1), r
'End If
End Sub
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim r As Integer
If Button = 1 Then
x2 = X
y2 = Y
r = Sqr((x1 - x2) ^ 2 + (y1 - y2) ^ 2)

这样最好:不要用picture,因为他有不透明的背景,让你的目的无法完美实现;使用一个shape来表示未定型的圆,定型后,使用画圆的方法直接画到窗体上。

代码如下:
Dim x0 As Single, y0 As Single, r As Single

Private Sub form_load()
Shape1.Shape = 3 '圆形,用来表示未定型的圆
Shape1.BorderStyle = 3 '虚线
Shape1.Visible = False '开始看不见
Me.AutoRedraw = True
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then '左键,记录圆心
x0 = X
y0 = Y
Form_MouseMove Button, Shift, X, Y '先移动到当前位置。
Shape1.Visible = True '现在就要可以看到
ElseIf Button = 2 Then '右键清除
Me.Cls
End If

End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim deltaX As Single, deltaY As Single, d As Single
If Button = 1 Then
deltaX = x0 - X '因为下面要用两次,所以要设立变量
delt