示例代码如下:
private void tbUnit_Click(object sender, EventArgs e)
{
TreeView tv = new TreeView();
tv.Location = new Point( tbUnit.Location.X+15, tbUnit.Location.Y+30);
tv.Size = new Size(tbUnit.Width, 200);
tv.Visible = true;
TreeNode node = new TreeNode("中国区");
tv.Nodes.Add(Wcf.WcfOpt.LoadUnitCatalog(node, "中国区"));
tv.ExpandAll();
this.Controls.Add(tv);
tv.BringToFront();
tv.MouseDoubleClick += new MouseEventHandler(this.onMouseDoubleClick);
tv.Show();
}
private void onMouseDoubleClick(object sender, MouseEventArgs e)
{
tbUnit.Text = ((TreeView)sender).SelectedNode.Text;
((TreeView)sender).Visible = false;
}
效果如下: