以下是效果
以下是设计
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO; namespace 抽奖 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void timer1_Tick(object sender, EventArgs e)//选择listbox.intem { Random rnd = new Random(); listBox1.SelectedIndex = rnd.Next(0, listBox1.Items.Count); } private void Form1_Load(object sender, EventArgs e) { string[] mystr = File.ReadAllLines(System.Environment.CurrentDirectory + "\\成员.txt", Encoding.Default); foreach (string x in mystr) { listBox1.Items.Add(x); } } private void button1_Click(object sender, EventArgs e) { timer1.Enabled = true; } private void button2_Click(object sender, EventArgs e) { timer1.Enabled = false; label1.Text = listBox1.SelectedItem.ToString(); } } }