vb题目计时器每0.1秒随机产生100个半径为100到150的位置在窗体的范围内的任意颜色的圆
2个回答
展开全部
'窗体拖入一个按钮、一个计时器
'复制以下代码
Private n As Integer
Private Sub draw()
w = Me.Width
h = Me.Height
Randomize
Dim x As Long
Dim y As Long
Dim r As Long
Dim rgb_r As Integer
Dim rgb_g As Integer
Dim rgb_b As Integer
rgb_r = Int(256 * Rnd)
rgb_g = Int(256 * Rnd)
rgb_b = Int(256 * Rnd)
r = Int(51 * Rnd + 100)
Randomize
x = Int(Rnd() * w)
y = Int(Rnd() * h)
Me.Circle (x, y), r, RGB(rgb_r, rgb_g, rgb_b)
End Sub
Private Sub Command1_Click()
If Me.Command1.Caption = "开始绘图" Then
Me.Cls
n = 0
Me.Timer1.Enabled = True
Me.Command1.Caption = "停止绘图"
Else
n = 0
Me.Timer1.Enabled = False
Me.Command1.Caption = "开始绘图"
End If
End Sub
Private Sub Form_Load()
n = 0
Me.Command1.Caption = "开始绘图"
Me.Timer1.Interval = 100
Me.Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
n = n + 1
If n <= 100 Then
Me.Command1.Caption = "停止绘图"
Call draw
Else
Me.Timer1.Enabled = False
Me.Command1.Caption = "开始绘图"
End If
End Sub
展开全部
Private Sub Form_Load()
Timer1.Interval = 100
End Sub
Private Sub Timer1_Timer()
Dim r As Double
r = Rnd * 50 + 100
Form1.Circle (Rnd * (Form1.Width - 2 * r) + r, Rnd * (Form1.Height - 2 * r) + r), r, RGB(Rnd * 255, Rnd * 255, Rnd * 255)
End Sub
Timer1.Interval = 100
End Sub
Private Sub Timer1_Timer()
Dim r As Double
r = Rnd * 50 + 100
Form1.Circle (Rnd * (Form1.Width - 2 * r) + r, Rnd * (Form1.Height - 2 * r) + r), r, RGB(Rnd * 255, Rnd * 255, Rnd * 255)
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询