新增一個元件
1 | public partial class UserControlRadioButton : RadioButton |
2 | { |
3 | /// <summary>判斷是否有改變Checked</summary> |
4 | private bool bCheckedChanged = false; |
5 | |
6 | public SLHRadioButton() |
7 | { |
8 | InitializeComponent(); |
9 | } |
10 | |
11 | protected override void OnCheckedChanged(EventArgs e) |
12 | { |
13 | base.OnCheckedChanged(e); |
14 | |
15 | this.bCheckedChanged = true; |
16 | } |
17 | |
18 | protected override void OnClick(EventArgs e) |
19 | { |
20 | this.bCheckedChanged = false; |
21 | |
22 | base.OnClick(e); |
23 | |
24 | if (this.Checked && !this.bCheckedChanged) this.Checked = false; |
25 | |
26 | this.bCheckedChanged = false; |
27 | } |
28 | } |