多语言展示
当前在线:107今日阅读:99今日分享:20

c#制作选号器 用来选学号抽奖器抽号器选号器

制作选号器 用来选学号抽奖器,抽号器
工具/原料
1

Microsoft visual studio 2010

2

电脑

方法/步骤
1

新建一个windows窗体

2

设置窗体如图,主要使用控件与textbox ,botton,lable,就够了

3

一个主程序,一个是窗体界面代码

4

如下using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace WindowsFormsApplication1{    public partial class 选学号器 : Form    {        public 选学号器()        {            InitializeComponent();        }        int b;        bool a = false;        bool c = false;        Timer t = new Timer();      //  int result = 0;        private void button1_Click(object sender, EventArgs e)        {                   try            {                t.Interval = timeset(1); //设置时间间隔,单位为毫秒                int min = int.Parse(textBox1.Text), max = int.Parse(textBox2.Text);                if (min >= max)                {                    MessageBox.Show('你输入的最大值小于最小值\n请重新输入');                       return;                }                if (t.Interval > 1000)                {                    MessageBox.Show('请输入大于0小于1000的值');                    return;                }               // minvalue(min);               // maxvalue(max);            }            catch (Exception ee)            {                MessageBox.Show(ee.Message);                textBox1.Focus();                return;            }                       a=!a;                    if(a)            {                c = false;                this.button1.Text = '停止';                              t.Start();                       }         else            {                c = true;               // while (b < 500)               // {               //     t.Interval+=b;               // }                for (; t.Interval < 500; t.Interval++)                {                }                    this.button1.Text = '开始';                t.Stop();            }               }               private void 选学号器_Load(object sender, EventArgs e)        {                        t.Tick += new EventHandler(t_tick);//添加委托        }        private void t_tick(object sender,EventArgs h)        {            int min = minvalue(1);            int max = maxvalue(1);                       if(c)            b++;            Random r = new Random();                show.Text = r.Next(min, max+1).ToString();                              }               private int minvalue(  int mi)        {          mi = int.Parse(textBox1.Text);            return mi;        }        private int maxvalue(int max)        {            max = int.Parse(textBox2.Text);            return max;        }        private int timeset(int time)        {            time = int.Parse(textBox3.Text);            return time;        }         }}

5

窗体代码太多字发不出去就不发了

6

就这样做好好按ctrl+f5运行,希望对你有帮助

注意事项

注意两个代码的区分

推荐信息