本文主要介绍了c#抽签系统的实现示例,一个基于c#的简单抽签系统,可以重新导入数据,清空数据。文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
一个基于c#的简单抽签系统,可以重新导入数据,清空数据。
代码简单,比较适合初学者。
导入数据时会创建一个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# 抽签系统内容请搜索得得之家以前的文章希望大家以后多多支持得得之家!
沃梦达教程
本文标题为:c#抽签系统的实现示例


基础教程推荐
猜你喜欢
- C# List实现行转列的通用方案 2022-11-02
- 一个读写csv文件的C#类 2022-11-06
- C#类和结构详解 2023-05-30
- ZooKeeper的安装及部署教程 2023-01-22
- winform把Office转成PDF文件 2023-06-14
- C#控制台实现飞行棋小游戏 2023-04-22
- linux – 如何在Debian Jessie中安装dotnet core sdk 2023-09-26
- C# 调用WebService的方法 2023-03-09
- unity实现动态排行榜 2023-04-27
- C# windows语音识别与朗读实例 2023-04-27