点名神器安装包:
链接: http://pan.baidu.com/s/1gdk5mqJ 密码: myf3
效果图:
代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace dianming
{
public partial class Form1 : Form
{
int k= 0;//用于循环
public Form1()
{
InitializeComponent();
timer1.Tick += new EventHandler(timer1_Tick);//定时器
}
private void timer1_Tick(object sender, EventArgs e)
{
String name = System.IO.Directory.GetCurrentDirectory() + "//name.txt";//读取文本路径
String[] na = File.ReadAllLines(name, Encoding.Default);
k ++;
Random rand = new Random(System.Guid.NewGuid().GetHashCode());
if (k < na.Length)
{
tb1.Text = na[rand.Next(0,na.Length )].ToString();//赋值给文本框tb1
}
else//一个循环结束
{
k = 0;
}
}
private void b1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;//开启定时器
}
private void b2_Click(object sender, EventArgs e)
{
timer1.Enabled = false;//关闭定时器
}
private void button1_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}