溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

c#抽簽系統(tǒng)如何實現

發(fā)布時間:2021-11-01 09:08:48 來源:億速云 閱讀:180 作者:小新 欄目:開發(fā)技術

這篇文章將為大家詳細講解有關c#抽簽系統(tǒng)如何實現,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

一個基于c#的簡單抽簽系統(tǒng),可以重新導入數據,清空數據。
代碼簡單,比較適合初學者。

c#抽簽系統(tǒng)如何實現

c#抽簽系統(tǒng)如何實現

導入數據時會創(chuàng)建一個txt文本,可以在里面看到輸入

private void button1_Click(object sender, EventArgs e)   //確定按鈕
        {
            string path = System.IO.Directory.GetCurrentDirectory() + "//name.txt";     
             Random rand = new Random(System.Guid.NewGuid().GetHashCode());               
             string[] name = File.ReadAllLines(path);                          
            if (name.Length == 0)
            {
                MessageBox.Show("導入數據不能為空!");
            }
            else
            {
                textBox1.Text = name[rand.Next(0, name.Length)];              //抽簽          
                textBox1.ForeColor = Color.Black;
            }
        }
         private void button3_Click(object sender, EventArgs e)     //導入數據
        {
            string qkong = "";                                                               //清空name.TXT
            string CurDir11 = System.AppDomain.CurrentDomain.BaseDirectory + @"name.txt.txt";    
            String filePath21 = CurDir11;
            System.IO.StreamWriter file11 = new System.IO.StreamWriter(filePath21, false);     /
            file11.Write(qkong);                                                                 
            file11.Close();                                                                   
            file11.Dispose();                                                                
            string result = textBox2.Text.Trim();                                          
            string d = System.AppDomain.CurrentDomain.BaseDirectory + @"name.txt";    
            String filePath = d;
            System.IO.StreamWriter file1 = new System.IO.StreamWriter(filePath, false);     
            file1.Write(result);                                                              
            file1.Close();                                                                 
            file1.Dispose();                                                                
            MessageBox.Show("導入成功");
        }
        private void button4_Click(object sender, EventArgs e)      //清空數據
        {
            string qkong = "";                                                              
            string s = System.AppDomain.CurrentDomain.BaseDirectory + @"name.txt.txt";   
            String filePath21 = s;
            System.IO.StreamWriter file11 = new System.IO.StreamWriter(filePath21, false);     
            file11.Write(qkong);                                                              
            file11.Close();                                                                  
            file11.Dispose();                                                                
            textBox2.Text = "";
        }
        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            this.textBox2.Multiline = true;
        }

關于“c#抽簽系統(tǒng)如何實現”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI