點名神器

點名神器安裝包:

鏈接: 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();
        }
    }
}
發佈了94 篇原創文章 · 獲贊 24 · 訪問量 12萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章