十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
你没有明白Timer控件的工作原理:
创新互联是一家专注于网站设计、网站制作与策划设计,藁城网站建设哪家好?创新互联做网站,专注于网站建设10年,网设计领域的专业建站公司;建站业务涵盖:藁城等地区。藁城做网站价格咨询:18980820575
你可以按照下面代码,做一个实验,然后体会,关键:
Timer控件按照其Interval设置的值,每间隔一定的时间,自动触发其Tick事件。
Public Class Form1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Text = Now
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
End Class
这是一个转盘 转到的位置是随机的 具体奖品需要你自己定 我就不帮你了..... 这一句 If c 95 Then Timer1.Interval = 0 这个95 改的越小 停的越快,转到的位置重复的几率也就越大 . 代码细看看, 数值都是活的 可以根据自己需要改.
'添加控件 timer1 command1 line1
Dim x1%, y1%
Dim a As String
Private Sub Command1_Click()
a = 0
Timer1.Interval = 50
End Sub
Private Sub form_load()
Me.AutoRedraw = True
x1 = Me.Width \ 2
y1 = (Me.Height - 405) \ 2
Line1.x1 = x1: Line1.y1 = y1
Me.DrawWidth = 5
Me.Circle (x1, y1), 3000
Line1.BorderWidth = 5
Line1.BorderColor = QBColor(14)
End Sub
Private Sub Timer1_Timer()
Randomize
c = Int((100) * Rnd + 1)
a = a + 1
If a 24 Then Timer1.Interval = 100
If a 40 Then Timer1.Interval = 200
If a 48 Then
Timer1.Interval = 300
If c 95 Then Timer1.Interval = 0
End If
b = (3.14 / 8) * a
Line1.X2 = Line1.x1 + (3000 * Sin(b))
Line1.Y2 = Line1.y1 - (3000 * Cos(b))
End Sub
我用多线程写的,你可以参考下。
系统界面图如下:(注:重置功能为清除已经中奖号码,回归1-100都可以中奖状态。)
代码:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
System.Threading.Thread g_Thread = null;
Listint g_list = new Listint();
int g_Num = 0;
delegate void g_delegate();
/// summary
/// 开始
/// /summary
/// param name="sender"/param
/// param name="e"/param
private void button2_Click(object sender, EventArgs e)
{
if(g_list.Count==100)
{
MessageBox.Show("所有数字已使用,请重置!");
return;
}
button3.Enabled = true;
Random r = new Random();
g_delegate dele= ChangeTxt;
g_Thread = new System.Threading.Thread(() =
{
while(this.IsDisposed==false)
{
g_Num = r.Next(1, 100);
if(g_list.Contains(g_Num))
{
g_Num = 1;
}
while(g_list.Contains(g_Num))
{
g_Num++;
}
this.Invoke(dele);
System.Threading.Thread.Sleep(50);
}
});
g_Thread.Start();
}
void ChangeTxt()
{
label2.Text = g_Num.ToString();
}
/// summary
/// 停止
/// /summary
/// param name="sender"/param
/// param name="e"/param
private void button3_Click(object sender, EventArgs e)
{
//if(g_Thread.ThreadState==System.Threading.ThreadState.Running)
{
g_Thread.Abort();
g_list.Add(Convert.ToInt32(label2.Text));
}
button3.Enabled = false;
}
/// summary
/// 重置
/// /summary
/// param name="sender"/param
/// param name="e"/param
private void button1_Click(object sender, EventArgs e)
{
g_list.Clear();
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
System.Environment.Exit(0);
}
}
随机数~~
定义数据结构
type 格子
奖品
编号
end type
定义一个转函数
sub 转()
转按钮.enable=false
格子=rnd()*最大格数
播放转的动画
定位到格子
if 有奖品 then
播放欢呼声音
else
播放失望声音
end if
转按钮.enable=true
end sub