sinat_32928967
JustinNiu
采纳率0%
2015-11-23 07:49

C#中做一个抽奖功能,然后抽奖名单通过已有的文档拖拽到C#程序中

只做好了抽奖代码

 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 抽奖综合Bata1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            开始抽奖ToolStripMenuItem.Enabled = false;
        }
        string[] namelist;
        int nameIndex = 0;
        private void 选取姓名列表ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog myFile = new OpenFileDialog();
            if (myFile.ShowDialog() == DialogResult.OK)
            {
                string FileName = myFile.FileName;
                namelist = File.ReadAllLines(FileName, Encoding.GetEncoding(0));
                nameIndex = 0;
                MessageBox.Show("你选中了:" + namelist.Length.ToString() + "个候选人");
                开始抽奖ToolStripMenuItem.Enabled = true;
            }
        }

        private void label1_Click(object sender, EventArgs e)
        {
            label1.Text = "一等奖:" + namelist[nameIndex];
            nameIndex = (nameIndex + 1) % namelist.Length;
        }

        private System.Windows.Forms.Timer myTimer;
        private void 开始抽奖ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            myTimer = new System.Windows.Forms.Timer();
            myTimer.Interval = 50;
            myTimer.Tick += new EventHandler(label1_Click);
            myTimer.Start();
        }


        private void button1_Click(object sender, EventArgs e)
        {
            if (myTimer != null)
                myTimer.Stop();
        }

将文本拖拽到C#程序中然后就可以就开始抽奖怎么来实现?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

相关推荐