adsense

顯示具有 c# 標籤的文章。 顯示所有文章
顯示具有 c# 標籤的文章。 顯示所有文章

2012-04-24

checkedListBox


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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string list = "";
            for (int i = (checkedListBox1.Items.Count - 1); i >= 0; i--)
            {
                if (checkedListBox1.GetItemChecked(i))
                {
                    list = checkedListBox1.Items[i].ToString();
                    checkedListBox1.Items.Remove(checkedListBox1.Items[i]);
                    checkedListBox2.Items.Add(list);
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string list = "";
            for (int i = (checkedListBox2.Items.Count - 1); i >= 0; i--)
            {
                if (checkedListBox2.GetItemChecked(i))
                {
                    list = checkedListBox2.Items[i].ToString();
                    checkedListBox2.Items.Remove(checkedListBox2.Items[i]);
                    checkedListBox1.Items.Add(list);

                }
            }
        }

        private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            checkedListBox1.CheckOnClick = true;
        }

        private void checkedListBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            checkedListBox2.CheckOnClick = true;
        }

     
    }
}

2012-04-17

listbox 練習



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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string list="";
            for (int i = (listBox1.Items.Count - 1); i >= 0; i--)
            {
                if (listBox1.GetSelected(i))
                {
                    list = listBox1.Items[i].ToString();
                    listBox1.Items.Remove(listBox1.Items[i]);
                    listBox2.Items.Add(list);
                }
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            string list="";
            for (int i = (listBox2.Items.Count - 1); i >= 0; i--)
            {
                if (listBox2.GetSelected(i))
                {
                    list=listBox2.Items[i].ToString();
                    listBox2.Items.Remove(listBox2.Items[i]);
                    listBox1.Items.Add(list);
           
                }
            }

        }

    }
}


2012-03-20

時間




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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private DateTime data;
        private void Form1_Load(object sender, EventArgs e)
        {
            label1.Text = "";
            label1.Font = new Font("標楷體", 24, FontStyle.Bold);
            timer1.Interval = 500;
            data = new DateTime(2012, 1, 1);
            this.Text = data.Year.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true;
         
        }

       private void button2_Click(object sender, EventArgs e)
        {
            timer1.Enabled = false;
        }


        private void button3_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
         
            label1.Text = data.Month + "月" + data.Day + "日";
           data = data.AddDays(1);
        }

     

        }
    }

2012-03-13

c# 四則運算



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 WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            text_all();
            TextChanged_all();
        }

        private void txt_TextChanged(object sender, EventArgs e)
        {
            try
            {
                double n = double.Parse(textBox1.Text) + double.Parse(textBox2.Text);
                textBox3.Text = n.ToString();
            }
            catch (Exception ex)
            { }
        }
        private void txt_TextChanged1(object sender, EventArgs e)
        {
            try
            {
                double n = double.Parse(textBox4.Text) - double.Parse(textBox5.Text);
                textBox6.Text = n.ToString();
            }
            catch (Exception ex)
            { }
        }
        private void txt_TextChanged2(object sender, EventArgs e)
        {
            try
            {
                double n = double.Parse(textBox7.Text) * double.Parse(textBox8.Text);
                textBox9.Text = n.ToString();
            }
            catch (Exception ex)
            { }
        }
        private void txt_TextChanged3(object sender, EventArgs e)
        {
            try
            {
                double n = double.Parse(textBox10.Text) / double.Parse(textBox11.Text);
                textBox12.Text = n.ToString();
            }
            catch (Exception ex)
            { }
        }
        private void text_all()
        {
            textBox1.Text = "0";
            textBox2.Text = "0";
            textBox3.Text = "0";
            textBox4.Text = "0";
            textBox5.Text = "0";
            textBox6.Text = "0";
            textBox7.Text = "0";
            textBox8.Text = "0";
            textBox9.Text = "0";
            textBox10.Text = "0";
            textBox11.Text = "0";
            textBox12.Text = "0";
        }
        private void TextChanged_all()
        {
            textBox1.TextChanged += new EventHandler(txt_TextChanged);
            textBox2.TextChanged += new EventHandler(txt_TextChanged);


            textBox3.TextChanged += new EventHandler(txt_TextChanged);
            textBox4.TextChanged += new EventHandler(txt_TextChanged1);


            textBox5.TextChanged += new EventHandler(txt_TextChanged1);
            textBox6.TextChanged += new EventHandler(txt_TextChanged1);


            textBox7.TextChanged += new EventHandler(txt_TextChanged2);
            textBox8.TextChanged += new EventHandler(txt_TextChanged2);


            textBox9.TextChanged += new EventHandler(txt_TextChanged2);
            textBox10.TextChanged += new EventHandler(txt_TextChanged3);


            textBox11.TextChanged += new EventHandler(txt_TextChanged3);
            textBox12.TextChanged += new EventHandler(txt_TextChanged3);

        }
    }
}