十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
这篇文章主要为大家展示了“如何使用编程语言实现随机点名程序”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“如何使用编程语言实现随机点名程序”这篇文章吧。
茅箭网站制作公司哪家好,找创新互联!从网页设计、网站建设、微信开发、APP开发、响应式网站设计等网站项目制作,到程序开发,运营维护。创新互联于2013年创立到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联。
using System; using System.Collections.Generic; using System.IO; using System.Windows.Forms; using System.Drawing; namespace Randoms { public partial class Main : Form { FileStream fs = null; StreamReader sr = null; //StreamWriter sw = null; Listnames = new List (); Random rd = new Random(); int jg = 0; //string syspath = System.Environment.CommandLine;//当前程序路径 string syspath = System.Windows.Forms.Application.StartupPath; public Main() { InitializeComponent(); //GetData();//获取数据 } private void GetData() { string Namesaddress = syspath + "\\Names.txt"; try { fs = new FileStream(Namesaddress, FileMode.Open); sr = new StreamReader(fs); //string count=sr.ReadLine(); //while (count!=null) //{ // name.Add(count.ToString()); //} while (true) { string s = sr.ReadLine(); if (s != null) names.Add(s); else break; } } catch (Exception) { throw; } finally { sr.Close(); fs.Close(); } } /// /// 开始点名 /// /// /// private void button1_Click(object sender, EventArgs e) { this.button2.Enabled = true; lab.ForeColor = Color.Black; if (names.Count == 0) { this.time.Enabled = false; lab.Text = "Please Reload At First"; } else { this.time.Enabled = true; } } ////// 计数器 /// /// /// private void time_Tick(object sender, EventArgs e) { int rf = names.Count; jg = rd.Next(0, rf); lab.Text = names[jg]; } ////// 停止 /// /// /// private void button2_Click(object sender, EventArgs e) { if (names.Count == 0) { this.time.Enabled = false; lab.Text = "The End"; //GetData(); } else { lab.ForeColor = Color.Blue; this.time.Enabled = false; names.RemoveAt(jg); } } ////// 加载所有人 /// /// /// private void Main_Load(object sender, EventArgs e) { string Namesaddress = syspath + "\\Names.txt"; if (System.IO.File.Exists(Namesaddress) ) { GetData(); } else { MessageBox.Show("查看Names.txt文件是否存在"); Application.Exit(); } } ////// 从新加载 /// /// /// private void button3_Click(object sender, EventArgs e) { lab.ForeColor = Color.Black; this.time.Enabled = false; lab.Text = "Load Complete"; GetData(); this.button2.Enabled = false; } } }
以上是“如何使用编程语言实现随机点名程序”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联行业资讯频道!