c#抽签系统

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;
        }
        



`

  • 9
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值