我有一个简单的情况(.NET2):UserControl1(或Form1)上的texbox1. 当我点击usercontrol / form时,我想要取消聚焦(离开)texbox(改为聚焦usercontrol / form): alt text http://lh3.ggpht.com/_1TPOP7DzY1E/S0R1ORVt-pI/AAAAAA
当我点击usercontrol / form时,我想要取消聚焦(离开)texbox(改为聚焦usercontrol / form):
alt text http://lh3.ggpht.com/_1TPOP7DzY1E/S0R1ORVt-pI/AAAAAAAAC3Y/UkS2zEMWa9o/s800/Capture4.png
我在UC /表格上执行以下操作:
Protected Overrides Sub OnMouseClick _ (ByVal e As System.Windows.Forms.MouseEventArgs) MyBase.OnMouseClick(e) Me.Focus() End Sub
为什么它不适用于子文本框,但在非子文本框上工作得很好(关注textBox2然后单击面板会从textBox2中删除焦点)?
真实的项目窗口
alt text http://lh5.ggpht.com/_1TPOP7DzY1E/S0SVniaeN1I/AAAAAAAAC3g/jafhFG-vA0g/s800/Capture5.png
>在表单中添加一个新的面板控件(在某处),并将其调整为0,0>请勿在此面板上设置Visible = false.
>在表单中添加标准MouseClick事件处理程序,如下所示:
private void Form1_MouseClick(object sender, MouseEventArgs e) { // Uncomment if in scrollable control //Point scrollPos = new Point(this.AutoScrollPosition.X, -this.AutoScrollPosition.Y); newPanel.Select(); // Uncomment if in scrollable control //this.AutoScrollPosition = scrollPos; }
>现在,当您单击主窗体上的任何位置时,任何输入控件都将失去焦点,您将能够处理通常的验证事件等.