CheckStateChanged(復選框選中狀態更改事件)和 CheckedChanged(單選按鈕選中狀態更改事件)二者區別?
在學習復選框控件(CheckBox)和單選按鈕控件(RadioButton)用到了上述兩種事件,但不明白有何區別:
1 using System; 2 using System.Data; 3 using System.Drawing; 4 using System.Text; 5 using System.Windows.Forms; 6 namespace Test18 7 { 8 public partial class Form1 : Form 9 { 10 public Form1() 11 { 12 InitializeComponent(); 13 } 14 private void checkBox1_CheckStateChanged(object sender, EventArgs e) 15 { 16 MessageBox.Show("控件的選擇狀態發生改變"); 17 } 18 19 private void Form1_Load(object sender, EventArgs e) 20 { 21 22 } 23 24 private void checkBox1_CheckedChanged(object sender, EventArgs e) 25 { 26 27 } 28 } 29 }
1 using System; 2 using System.Data; 3 using System.Drawing; 4 using System.Text; 5 using System.Windows.Forms; 6 namespace Test20 7 { 8 public partial class Form1 : Form 9 { 10 public Form1() 11 { 12 InitializeComponent(); 13 } 14 private void radioButton1_CheckedChanged(object sender, EventArgs e) 15 { 16 MessageBox.Show("RadioButton1控件的選中狀態被更改"); 17 } 18 private void button1_Click(object sender, EventArgs e) 19 { 20 radioButton1.Checked = true; 21 } 22 private void button2_Click(object sender, EventArgs e) 23 { 24 radioButton1.Checked = false; 25 } 26 private void Form1_Load(object sender, EventArgs e) 27 { 28 radioButton1.Checked = true; 29 } 30 } 31 }