在窗体上增加一个 Shape 控件,样式设为圆,名字为 Shape1
在窗体上增加一个文本框,一个按钮,用来输入自定义圆半径
本例中不隐藏鼠标箭头,如果需要隐藏,请自行使用相关API进行隐藏.
或显示为十字形都可以.
'-------------代码------------------------
Option Explicit
'保存鼠标位置及圆的半径
Dim MX As Long, MY As Long, R As Long
Private Sub Command1_Click()
'修改 半径
Dim i As Long
i = Val(Text1.Text)
If i > 15 Then
Shape1.Width = i * 2
Shape1.Height = i * 2
R = i
End If
End Sub
Private Sub Form_Click()
'单击
'如果前面是显示圆,则进行擦除
If Shape1.Visible Then
Me.FillStyle = 0
Me.FillColor = Me.BackColor
Me.Circle (MX, MY), R, Me.BackColor
End If
'显示与不显示切换
Shape1.Visible = Not Shape1.Visible
End Sub
Private Sub Form_Load()
'设置初始的图的大小
R = 500
Shape1.Width = 2 * R
Shape1.Height = 2 * R
'画些线条,以便显示擦除的效果
Dim x1 As Long, y1 As Long
Dim i As Long
For i = 1 To 1000
Me.Line -(Rnd() * Me.Width, Rnd() * Me.Height), Rnd() * 16777215
Next i
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'移动鼠标下的圆
MX = X
MY = Y
Shape1.Move X - R, Y - R
End Sub