ActiveControl只能指向SplitContainer (转)
因为splitContainer也是控件Control,所以窗体的ActiveControl为splitContainer也是合理的,但是可能我们对这样的窗口控件为ActiveControl并不太喜欢,我们需要的是像TextBox,Button等最基本的控件为ActiveControl,所以可以如下获取窗体的ActiveControl:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
protected override void OnClick(EventArgs e){ Control activeControl = this.getActiveControl(); base.OnClick(e);}private Control getActiveControl(){ Control activeControl = this.ActiveControl; while ((activeControl as ContainerControl) != null) { activeControl = (activeControl as ContainerControl).ActiveControl; } return activeControl;} |
浙公网安备 33010602011771号