VB设计一个随机抽奖程序,当单击开始按钮时,在两个文本框产生【1,20】之间的随机整数?

VB设计一个随机抽奖程序,当单击开始按钮时,在两个文本框产生【1,20】之间的随机整数?,第1张

假定开始按钮是 Command1,两个文本框分别是 Text1、Text2

Private Sub Command1_Click()

Randomize

Text1.Text = Int(Rnd * 20) + 1

Text2.Text = Int(Rnd * 20) + 1

End Sub

在窗体上添加一个command1,一个timer1,label1(0~5)

控件数组(添加一个label1,然后再复制5个,共6个,用来显示数字),代码如下:

Private

Sub

Command1_Click()

If

Command1.Caption

=

"抽奖"

Then

Command1.Caption

=

"停止"

Timer1.Enabled

=

True

Else

Timer1.Enabled

=

False

Command1.Caption

=

"抽奖"

End

If

End

Sub

Private

Sub

Form_Load()

Command1.Caption

=

"抽奖"

Timer1.Interval

=

50

Timer1.Enabled

=

False

End

Sub

Private

Sub

Timer1_Timer()

Randomize

For

i

=

0

To

5

Label1(i)

=

Int(10

*

Rnd)

Select

Case

Label1(i).Caption

Case

0

Label1(i).BackColor

=

RGB(0,

0,

0)

Label1(i).ForeColor

=

RGB(255,

255,

255)

Case

1

Label1(i).BackColor

=

RGB(128,

42,

42)

Label1(i).ForeColor

=

RGB(127,

213,

213)

Case

2

Label1(i).BackColor

=

RGB(255,

0,

0)

Label1(i).ForeColor

=

RGB(0,

255,

255)

Case

3

Label1(i).BackColor

=

RGB(255,

97,

0)

Label1(i).ForeColor

=

RGB(0,

158,

255)

Case

4

Label1(i).BackColor

=

RGB(255,

255,

0)

Label1(i).ForeColor

=

RGB(0,

0,

255)

Case

5

Label1(i).BackColor

=

RGB(0,

255,

0)

Label1(i).ForeColor

=

RGB(255,

0,

255)

Case

6

Label1(i).BackColor

=

RGB(0,

0,

255)

Label1(i).ForeColor

=

RGB(255,

0,

0)

Case

7

Label1(i).BackColor

=

RGB(160,

32,

240)

Label1(i).ForeColor

=

RGB(95,

223,

15)

Case

8

Label1(i).BackColor

=

RGB(192,

192,

192)

Label1(i).ForeColor

=

RGB(63,

63,

63)

Case

9

Label1(i).BackColor

=

RGB(255,

255,

255)

Label1(i).ForeColor

=

RGB(0,

0,

0)

End

Select

Next

End

Sub


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11060073.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-13
下一篇 2023-05-13

发表评论

登录后才能评论

评论列表(0条)

保存