日期:2014-05-18  浏览次数:21090 次

问一个关于ToolStripDropDown焦点的问题
照着msdn做一个自定义的comboxTreeView,代码如下:
  public class MyCombo : textbox
  {  
  ToolStripControlHost treeViewHost;
  ToolStripDropDown dropDown;
  public MyCombo()
  {
  TreeView treeView = new TreeView();
  treeView.BorderStyle = BorderStyle.None;
  treeViewHost = new ToolStripControlHost(treeView);
  dropDown = new ToolStripDropDown();
  dropDown.Items.Add(treeViewHost);
   
  this.GotFocus += new EventHandler(MyCombo_GotFocus)

  }

  public TreeView TreeView
  {
  get { return treeViewHost.Control as TreeView; }
  }

  private void ShowDropDown()
  {
  if (dropDown != null)
  {
  treeViewHost.Width = DropDownWidth;
  treeViewHost.Height = DropDownHeight;
  dropDown.Show(this, 0, this.Height);
  }
  }

  void MyCombo_GotFocus(object sender, EventArgs e)
  {
  ShowDropDown();
  return;
  }
   
  protected override void Dispose(bool disposing)
  {
  if (disposing)
  {
  if (dropDown != null)
  {
  dropDown.Dispose();
  dropDown = null;
  }
  }
  base.Dispose(disposing);
  }
  }
}

因为我想在textbox获得焦点时,让dropdown显示,结果是dropdown显示了,但是焦点却不见了。请问如何使dropDown显示的时候,焦点还是在原来的控件那?


------解决方案--------------------
探讨
dropDown.AutoClose = false;