十年網(wǎng)站開(kāi)發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營(yíng)維護(hù)+專(zhuān)業(yè)推廣+無(wú)憂售后,網(wǎng)站問(wèn)題一站解決
這篇文章主要為大家展示了“如何使用編程語(yǔ)言實(shí)現(xiàn)隨機(jī)點(diǎn)名程序”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“如何使用編程語(yǔ)言實(shí)現(xiàn)隨機(jī)點(diǎn)名程序”這篇文章吧。
茅箭網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)!從網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開(kāi)發(fā)、APP開(kāi)發(fā)、響應(yīng)式網(wǎng)站設(shè)計(jì)等網(wǎng)站項(xiàng)目制作,到程序開(kāi)發(fā),運(yùn)營(yíng)維護(hù)。創(chuàng)新互聯(lián)于2013年創(chuàng)立到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來(lái)保證我們的工作的順利進(jìn)行。專(zhuān)注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)。
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;//當(dāng)前程序路徑 string syspath = System.Windows.Forms.Application.StartupPath; public Main() { InitializeComponent(); //GetData();//獲取數(shù)據(jù) } 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(); } } /// /// 開(kāi)始點(diǎn)名 /// /// /// 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; } } ////// 計(jì)數(shù)器 /// /// /// 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; } } }
以上是“如何使用編程語(yǔ)言實(shí)現(xiàn)隨機(jī)點(diǎn)名程序”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!