C#初学者,谁能提供一些简单的代码,小程序等???

解决方案 »

  1.   

    在http://download.csdn.net/很多可下载
      

  2.   

    小程序/窗体传值
    窗体1又一个listbox和一个按钮
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Collections;namespace Mytest
    {
        public partial class Form1 : Form
        {
            ArrayList arraylist;
            public Form1()
            {
                InitializeComponent();
                arraylist = new ArrayList();
                arraylist.Add("aa");
                arraylist.Add("bb");
                arraylist.Add("vv");
                arraylist.Add("cc");
                listBox1.DataSource = arraylist;
            }        private void button1_Click(object sender, EventArgs e)
            {
                Form2 f2 = new Form2(arraylist);
                f2.ShowDialog();
                listBox1.DataSource = null;
                listBox1.DataSource = arraylist;
            }        private void Form1_Load(object sender, EventArgs e)
            {        }
        }
    }
    窗体2有一个listbox和按钮1按钮2按钮3
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Collections;namespace Mytest
    {
        public partial class Form2 : Form
        {
            ArrayList arraylist2;
            public Form2(ArrayList arraylist3)
            {
                InitializeComponent();
                arraylist2 = new ArrayList();
                arraylist2 = arraylist3;
                foreach (object obj in arraylist2)
                {
                    listBox1.Items.Add(obj);
                }
            }        private void Form2_Load(object sender, EventArgs e)
            {        }        private void button1_Click(object sender, EventArgs e)
            {
                if (textBox1.Text.Length > 0)
                {
                    arraylist2.Add(textBox1.Text);
                    listBox1.Items.Add(textBox1.Text);
                }
                else 
                    MessageBox.Show("error");
            }        private void button2_Click(object sender, EventArgs e)
            {
                int i = listBox1.SelectedIndex;
                if (i > -1)
                {
                    arraylist2.RemoveAt(i); ;
                    listBox1.Items.RemoveAt(i);
                }
                else 
                    MessageBox.Show("error");
            }        private void button3_Click(object sender, EventArgs e)
            {
                this.Close();
            }
        }
    }