vb中,在picturebox控件中画圆的代码

要求,1、鼠标左键按下时的位置为圆心,拖拉的距离为半径画圆。2、鼠标可以选择此图形,并可以移动此图。... 要求,1、鼠标左键按下时的位置为圆心,拖拉的距离为半径画圆。
2、鼠标可以选择此图形,并可以移动此图。
展开
 我来答
百度网友7b633ce
2010-12-22 · TA获得超过593个赞
知道大有可为答主
回答量:653
采纳率:0%
帮助的人:757万
展开全部
Option Explicit
Dim Dx, Dy As Integer 'mousedown
Dim Cx, Cy As Integer 'center of circle
Dim MouseDown As Boolean 'mouse is down
Dim isExists As Boolean 'circle exists
Dim Cr As Single 'radius

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If vbLeftButton = Button Then
MouseDown = True
Dx = X
Dy = Y
Else
'clear circle
Picture1.Cls
isExists = False
End If
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not MouseDown Then Exit Sub
If isExists Then

If Sqr((Abs(X - Cx)) ^ 2 + (Abs(Y - Cy)) ^ 2) > Cr Then
Exit Sub 'out of area
End If
'move circle
Dim Mx, My As Integer
Mx = X - Dx
My = Y - Dy

Cx = Cx + Mx
Cy = Cy + My

Dx = X
Dy = Y

Picture1.Cls
'draw new circle
Picture1.Circle (Cx, Cy), Cr
Else
Picture1.Cls
'draw new circle
Cr = Sqr((Abs(X - Dx)) ^ 2 + (Abs(Y - Dy)) ^ 2)
Picture1.Circle (Dx, Dy), Cr
Cx = Dx 'center
Cy = Dy
End If
End Sub

Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If vbLeftButton = Button Then
'circle is ok
MouseDown = False
isExists = True
End If
End Sub
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式