首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

小弟我是新手. 提出一些简单的C# 有关问题. 望高手解答,轻喷.

2013-08-04 
我是新手. 提出一些简单的C# 问题. 望高手解答,轻喷...我是新手,刚接触C#我做一个程序,用户输入3组数据,Na

我是新手. 提出一些简单的C# 问题. 望高手解答,轻喷...
我是新手,刚接触C#
我做一个程序,用户输入3组数据,Name;Brand;Size;存入一个类。
然后将这个类的实例存入一个Checklistbox。
现在要加一个线程,每分钟都存入checklistbox一个类。这三组数据都随机,随便输入什么都行。
还能添加到这个checklistbox中。
线程的问题,我没接触过。望高手说明一下。谢谢啦!跪谢。
public class Car
    {
        public Name name;
        public Brand brand;
        public Size size;

        
        public Car(Name n1,Brand b1,Size s1)
        {
            name = n1;
            brand = b1;
            size = s1;
        }
    }
public class Name 
    {
        public string type;
        public Name(string myname)
        {
            type = myname;
        }
    }

public void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length == 0 || textBox2.Text.Length == 0 || textBox3.Text.Length == 0)
                return;
            Name n1 = new Name(this.textBox1.Text);
            Brand b1 = new Brand(this.textBox2.Text);
            Size s1 = new Size(this.textBox3.Text);
            Car car1 = new Car(n1, b1, s1);
            Cangku.al_Car.Add(car1);
            fm1.showCar();
            this.textBox1.Clear();
            this.textBox2.Clear();


            this.textBox3.Clear();
            this.Visible = false;
        }

public void showCar()
        {
            this.checkedListBox1.Items.Clear();
            for (int i = 0; i < Cangku.al_Car.Count; i++)
            {
                Car mycar = (Car)Cangku.al_Car[i];
                this.checkedListBox1.Items.Add(mycar.name.type+ "的车");
            }
        }


谢谢各位大哥了!  求能写的详细一点!!!
新手 跪谢!


public delegate void AddCheck(string val);//委托
        public int flag = 0;
        void ExecuteWork(object sender, ElapsedEventArgs e)
        {
            flag++;
            this.Invoke(new AddCheck(AddCheckHandler), new object[] { flag.ToString() });
        }
        void AddCheckHandler(string val)


        {
            checkedListBox1.Items.Add(val);
        }
        public Formo()
        {
            InitializeComponent();

            System.Timers.Timer tm = new System.Timers.Timer(6000);//6秒
            tm.Elapsed += new System.Timers.ElapsedEventHandler(ExecuteWork);
            tm.AutoReset = true;
            tm.Enabled = true;
}


该例演示了 线程对UI线程控件checkedListBox1 定时添加项操作

热点排行