在线等:VB 画圆,为什么一次可以画出同心圆

2024-12-17 06:52:26
推荐回答(4个)
回答1:

你放你的代码出来看看呀..

应该是你在2个事件中都添加了代码,造成了画了多个圆..

你要知道mouse down,mouse up这其实是一个连续的动作, 你可以将画圆的代码添加在鼠标按下时,或是鼠标弹起时..

如果你2个都加了,就相当于按下时画了一个圆,弹起时,又画了一个..

回答2:

Option Explicit
Dim rx, ry
Dim maxr As Integer
Dim intv As Integer
private sub command1_click() '设置
maxr = 7.5 * Val(InputBox("圆的最大直径(像素)", , 200))
intv = 15 * Val(InputBox("间距", , 20))
end sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
rx = X
ry = Y

End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim r
For r = intv To maxr Step intv
Circle (rx, ry), r, 256 ^ 3 * Rnd

Next r
End Sub

回答3:

我做了一个,点一下开始画,移动鼠标可以看到,松开鼠标画出来,但有个缺陷就是当画后面的圆时如果与其相交会搽掉一部分。
Option Explicit

Private rx As Long, ry As Long, isDraw As Boolean

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
rx = X
ry = Y
isDraw = True
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Static oldx As Long, oldy As Long, oldcolor As Long
oldcolor = Me.ForeColor
If isDraw Then
Me.ForeColor = Me.BackColor
Me.Circle (rx, ry), Sqr((oldx - rx) * (oldx - rx) + (oldy - ry) * (oldy - ry))
Me.ForeColor = oldcolor
Me.Circle (rx, ry), Sqr((X - rx) * (X - rx) + (Y - ry) * (Y - ry))
End If
oldx = X
oldy = Y
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
isDraw = False
End Sub

回答4:

只画一个,将函数放在mouse down中就行了,按下时执行。当然,放在mouse Up中也行,放开时执行。但因只需要一个园,所以该函数也只应该执行一次。