同学做的,源代码 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.IO; using System.Windows.Forms;namespace 点名程序 { public partial class Form1 : Form { public Form1() { InitializeComponent(); arr =File.ReadAllLines("名单.txt",Encoding.GetEncoding("gb2312")); pictureBox1.Image = Image.FromFile("照片/***********.jpg"); this.label1.Text = "中奖的同学是:*********** 8888" ;
label1.Text = new Random().Next(0, 100).ToString(); //假设有100个人,编号1-100
在button1里面写timer1.Enabled = !timer1.Enabled;
搞定。
我也是初学者,这里有免费的视频,我也经常上去看
http://school.itzcn.com/index.html
public void TAward(Label lab)
{
Random rnd=new Random();
lab.Text = rnd.Next(0, 9).ToString();
}
然后建立一个form
拖一个button
一个timer
和几个label (我这里用的6个)在form中输入如下代码 一个简单的抽奖程序就出来啦 Class1 myClass = new Class1();
private void button1_Click(object sender, EventArgs e)
{
if (button1.Text == "开始抽奖")
{
button1.Text = "停止抽奖";
timer1.Start();
}
else if (button1.Text == "停止抽奖")
{
button1.Text = "开始抽奖";
timer1.Stop();
label7.Text = "本期中奖号码:" + label1.Text + label2.Text + label3.Text + label4.Text + label5.Text + label6.Text;
}
} private void timer1_Tick(object sender, EventArgs e)
{
myClass.TAward(label1);
Thread.Sleep(100);
myClass.TAward(label2);
Thread.Sleep(100
myClass.TAward(label3
Thread.Sleep(100);
myClass.TAward(label4);
Thread.Sleep(100);
myClass.TAward(label5);
Thread.Sleep(100);
myClass.TAward(label6);
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO;
using System.Windows.Forms;namespace 点名程序
{ public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
arr =File.ReadAllLines("名单.txt",Encoding.GetEncoding("gb2312"));
pictureBox1.Image = Image.FromFile("照片/***********.jpg");
this.label1.Text = "中奖的同学是:*********** 8888" ;
} private void label1_Click(object sender, EventArgs e)
{
} private void timer1_Tick(object sender, EventArgs e)
{
int flag;
Random r = new Random();
flag = r.Next(arr.Length);
this.label1.Text="中奖的同学是:"+arr[flag];
} private void button1_Click(object sender, EventArgs e)
{
if (this.timer1.Enabled==false)
{
this.timer1.Enabled=true;
this.button1.Text = "停止";
}
else
{
this.timer1.Enabled =false;
this.button1.Text = "开始";
}
} private void Form1_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
Form fm = new Form2();
fm.ShowDialog();
} private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
}
}