WCF随机抽取

逻辑层代码

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

 

namespace AskQuestionInClass

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        string filename = null;

        private void button1_Click(object sender, EventArgs e)

        {

            if (openFileDialog1.ShowDialog() == DialogResult.OK)

            {

                //如果选择文件后,点击OK按钮则将选区文件赋值给FileDialog

                filename = openFileDialog1.FileName;

                //openFileDialog1.FileName;FileName是包含了文件路劲和文件名字的一个字符串

            }

            else

            {

                MessageBox.Show("你没有选择文件!是否放弃选择?");

                return;

            }

        }

 

        //集合 list<>;dictiongary<,>或者数组;

        List<string> studentlist;//用来储存学生名单,提供名单自动抽取时的载体

        string[] newstulist;//同来与文本文件名单对接,用来读取数据

        private void button2_Click(object sender, EventArgs e)

        {

            if (filename == "")

            {

                MessageBox.Show("没有选择班级名单或者名单为空");

                    return;

            }

            else

            {

                studentlist = System.IO.File.ReadAllLines(filename).ToList();

                //将文本文件的学生名单读取出来,存在list集合中

                if(button2.Text=="开始")

                {

                    timer1.Start();

                    button2.Text = "结束";

                }

                else

                {

                    timer1.Stop();

                    button2.Text = "开始";

                }

            }

        }

 

        private void timer1_Tick(object sender, EventArgs e)

        {

            Random rd1 = new Random();

            int temp = rd1.Next(0, studentlist.Count);//随即确定被读取对象

            label2.Text = studentlist[temp].ToString();//读值对象的值

            label2.ForeColor = Color.FromArgb(rd1.Next(0, 200 * 200));//变色

        }

 

        private void trackBar1_Scroll(object sender, EventArgs e)

        {

            timer1.Interval=trackBar1.Value;

        }

    }

}

 

支持TXT格式,其他格式会出现乱码

创建TXT文本

写几行文字就可以

运行窗体

选择你创建的TXT文本点击开始

点击结束随机选中

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值