c#抽簽系統的實現示例

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

在這裡插入圖片描述

導入數據時會創建一個txt文本,可以在裡面看到輸入

導入數據時會創建一個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 filePath11 = CurDir11;
            System.IO.StreamWriter file11 = new System.IO.StreamWriter(filePath11, 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 filePath11 = s;
            System.IO.StreamWriter file11 = new System.IO.StreamWriter(filePath11, false);     
            file11.Write(qkong);                                                              
            file11.Close();                                                                  
            file11.Dispose();                                                                
            textBox2.Text = "";
        }
        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            this.textBox2.Multiline = true;
        }

到此這篇關於c#抽簽系統的實現示例的文章就介紹到這瞭,更多相關c# 抽簽系統內容請搜索WalkonNet以前的文章或繼續瀏覽下面的相關文章希望大傢以後多多支持WalkonNet!

推薦閱讀: