首页 > 代码库 > c# windows编程控件学习-1

c# windows编程控件学习-1

  1 using System;  2 using System.Collections.Generic;  3 using System.ComponentModel;  4 using System.Data;  5 using System.Drawing;  6 using System.Linq;  7 using System.Text;  8 using System.Threading.Tasks;  9 using System.Windows.Forms; 10  11 namespace proj9_1 12 { 13     public partial class Form1 : Form 14     { 15         public Form1() 16         { 17             InitializeComponent(); 18         } 19  20         private void button1_Click(object sender, EventArgs e) 21         { 22             Form myform = new Form1_1(); 23             myform.ShowDialog(); 24  25         } 26  27         private void Form1_Load(object sender, EventArgs e) 28         { 29             //MessageBox.Show("3个按钮", "信息提示", MessageBoxButtons.AbortRetryIgnore); 30             listBox1.Items.Add("清华大学"); listBox1.Items.Add("北京大学"); 31             listBox1.Items.Add("北京航空航天大学"); listBox1.Items.Add("人民大学"); 32             listBox1.Items.Add("南京大学"); listBox1.Items.Add("武汉大学"); 33             listBox1.Items.Add("山东大学"); listBox1.Items.Add("复旦大学"); 34             enbutton(); 35         } 36  37         private void enbutton() 38         { 39             if (listBox1.Items.Count == 0) 40             { 41                 button7.Enabled = false; button8.Enabled = false; 42             } 43             else 44             { 45                 button7.Enabled = true; button8.Enabled = true; 46             } 47             if (listBox2.Items.Count == 0) 48             { 49                 button9.Enabled = false; button10.Enabled = false; 50             } 51             else 52             { 53                 button9.Enabled = true; button10.Enabled = true; 54             } 55         } 56  57         private void button2_Click(object sender, EventArgs e) 58         { 59             Form myform = new Form1_2(); 60             myform.Show(); 61         } 62  63         private void richTextBox1_TextChanged(object sender, EventArgs e) 64         { 65  66         } 67  68         private void groupBox1_Enter(object sender, EventArgs e) 69         { 70  71         } 72  73         private void checkBox1_CheckedChanged(object sender, EventArgs e) 74         { 75             MessageBox.Show("3个按钮", "信息提示", MessageBoxButtons.AbortRetryIgnore); 76         } 77  78         private void button3_Click(object sender, EventArgs e) 79         { 80             if (checkBox1.Checked && checkBox3.Checked && !checkBox2.Checked && !checkBox4.Checked) 81             { 82                 MessageBox.Show("您答对了,真的很棒!!!", "信息提示", MessageBoxButtons.OK); 83             } 84             else 85                 MessageBox.Show("您答错了,继续努力。", "信息提示", MessageBoxButtons.OK); 86         } 87  88         private void button4_Click(object sender, EventArgs e) 89         { 90             if (radioButton3.Checked) 91             { 92                 MessageBox.Show("您选对了", "提示", MessageBoxButtons.OK); 93             } 94             else if (radioButton1.Checked || radioButton4.Checked) 95             { 96                 MessageBox.Show("您选错了", "提示", MessageBoxButtons.OKCancel); 97             } 98             else 99             {100                 MessageBox.Show("您选错了,这是数据库系统", "提示", MessageBoxButtons.OKCancel);101             }102         }103 104         private void button5_Click(object sender, EventArgs e)105         {106             pictureBox1.Image = Image.FromFile("E:\\flac3d.jpg");107 108         }109 110         private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)111         {112 113         }114 115         private void button6_Click(object sender, EventArgs e)116         {117             if (textBox1.Text != "")118                 if (!comboBox1.Items.Contains(textBox1.Text))119                     comboBox1.Items.Add(textBox1);120         }121 122 123 124         private void button7_Click(object sender, EventArgs e)125         {126             if (listBox1.SelectedIndex >= 0)127             {128                 listBox2.Items.Add(listBox1.SelectedItem);129                 listBox1.Items.RemoveAt(listBox1.SelectedIndex);130             }131             enbutton();132         }133         private void button8_Click(object sender, EventArgs e)134         {135             foreach (var item in listBox1.Items)136             {137                 listBox2.Items.Add(item);138             }139             enbutton();140             listBox1.Items.Clear();141         }142 143     }144 }

 

 

 

技术分享

 

c# windows编程控件学习-1