窗体(随机数,列表框,标签,按钮,修改窗体名字)

来源:互联网 发布:诺可可网络 编辑:程序博客网 时间:2024/05/20 06:37

运行图片:


问题:


//8.设计如图实验8-8所示的窗体,窗体上有一个列表框、一个标签和一个按钮。
//利用Random类产生10个[10,99]之间的随机数,并将这10个随机数在列表框中显示出来,每个数占一项。用户选择某项后,在右边标签中显示所选内容

代码:

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 实验8._8{    public partial class Form1 : Form    {        Random rd=new Random();        String s;        public Form1()        {            InitializeComponent();                    }        private void Form1_Load(object sender, EventArgs e)        {            this.Text = "列表框实验";            button1.Text = "结束";            listBox1.Items.Add(rd.Next(10, 100));            listBox1.Items.Add(rd.Next(10, 100));            listBox1.Items.Add(rd.Next(10, 100));            listBox1.Items.Add(rd.Next(10, 100));            listBox1.Items.Add(rd.Next(10, 100));            listBox1.Items.Add(rd.Next(10, 100));            listBox1.Items.Add(rd.Next(10, 100));            listBox1.Items.Add(rd.Next(10, 100));            listBox1.Items.Add(rd.Next(10, 100));            listBox1.Items.Add(rd.Next(10, 100));        }        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)        {            s = listBox1.SelectedItem.ToString();        }        private void button1_Click(object sender, EventArgs e)        {            label1.Text = s;        }    }}





0 0
原创粉丝点击