Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1162
  • 博文数量: 2
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 20
  • 用 户 组: 普通用户
  • 注册时间: 2013-05-09 22:33
文章分类

全部博文(2)

文章存档

2013年(2)

我的朋友
最近访客

分类: C#/.net

2013-05-31 12:54:57



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 Program1
{
    public partial class Form1 : Form
    {
        private int n;
        private int min, max;
        public Form1()
        {
            InitializeComponent();
        }


        private void button1_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            checkedListBox1.Items.Clear();
            try
            {
                n = Convert.ToInt32(textBox1.Text);
                min = Convert.ToInt32(textBox2.Text);
                max = Convert.ToInt32(textBox3.Text);
                if (n <= 0)
                {
                    MessageBox.Show("请输入大于 0 的个数值 !");
                }
                if (max <= min)
                {
                    MessageBox.Show("请输入大于 最小值的最大值 !");
                }
            }
            catch {
                MessageBox.Show("参数的 输入 有误 !");
            }
            Random r = new Random();
            List l = new List();
            for (int i = 0; i < n; i++)
            {
                l.Add(r.Next(min, max));
                listBox1.Items.Add(l[i]);
            }
            l.Sort();
            for (int i = 0; i < n; i++)
            {
                checkedListBox1.Items.Add(l[i]);
            }
        }


        private void button2_Click(object sender, EventArgs e)
        {
            CheckedListBox.CheckedItemCollection ci = checkedListBox1.CheckedItems;
            if (ci.Count != 0)
            {
                StringBuilder s = new StringBuilder();
                s.Append("你选择的数值 为 :");
                foreach (int i in ci)
                {
                    s.Append(i + "、 ");
                }
                MessageBox.Show(s.ToString());
            }
            else {
                MessageBox.Show("你没有选择任何数值 !");
            }
            
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace Program1
{
    static class Program
    {
        ///
        /// 应用程序的主入口点。
        ///
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}




阅读(169) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:没有了

给主人留下些什么吧!~~