窗体上有一个TreeView和若干个TextBox控件,我希望当点击treeview中的某个节点时能让指定的TextBox得到焦点。

用委托的异步来处理:  
   
  private   delegate   void   focusHandle();//定义委托  
  private   void   treeView1_AfterSelect(object   sender,   System.Windows.Forms.TreeViewEventArgs   e)  
  {  
  focusHandle   h   =   new   focusHandle(f);  
  h.BeginInvoke(null,h);//异步  
  }  
  private   void   f()  
  {  
  focusHandle   invoke   =   new   focusHandle(txtFocuse);  
  this.Invoke(invoke);  
  }  
  private   void   txtFocuse()  
  {  
  this.textBox1.Focus();  
  }
作者:wpf之家
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/wpf123/p/2347384.html