利用C#完成的随机点名系统
namespace 点名器1
{
public partial class call_name : Form
{
public call_name()
{
InitializeComponent();
}
double Fristtime = 0;
/// <summary>
/// i为计算之后的点击次数
/// </summary>
int i = 0;
/// <summary>
/// 同学姓名名单
/// </summary>
string[] stuName = new string[] { "赵同学", "钱同学", "孙同学",
"李同学", "周同学","吴同学",
"郑同学","王同学","冯同学","陈同学" };
/// <summary>
/// 利用timer生成随机数,利用随机数除于进行点名
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer1_Tick(object sender, EventArgs e)
{
Fristtime = Fristtime 0.1;
Random l = new Random();
int ll = l.Next();
int s = ll % 10;
this.namebox.Text = stuName[s];
}
/// <summary>
/// 单数点击开始随机点名,复数点击暂停名字滚动
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void start_Click(object sender, EventArgs e)
{
i ;
if (i % 2 == 1)
{
this.timer1.Enabled = true;
start.BackColor = Color.FromArgb(166, 33, 22);//按钮变色
start.ForeColor = Color.White;//字体变色
}
if (i % 2 == 0)
{
this.timer1.Enabled = false;
start.BackColor = Color.Red; //按钮变回原色
start.ForeColor = Color.Black;//字体变回原色
}
}
/// <summary>
/// 退出前提示
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
if (MessageBox.Show(this,
"确定要关闭当前窗体吗?是,请单击‘确定’\n按钮;否则,请单击‘取消’按钮。",
"提示",
MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
== DialogResult.OK)
{
this.Close();
}
}
}
}
评论