单击树视图中的节点后,我试图打开一个新表单。
在第一个 MDI 表单中,我有一个树视图,当我单击树视图中的一个节点时,会打开第二个 MDI 表单,但第一个表单保持焦点。我希望新表格具有焦点。
我注意到第一个表单的 _Enter 事件正在触发,好像某些东西正在将焦点设置回第一个表单。
第一个表单上还有一个按钮,它具有相同的功能并且效果很好。我有一种感觉,treeview 设置了一些特殊的属性,以使焦点回到第一种形式。
这是打开表单的代码
private void tvClientsAccounts_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
OpenClientOrAccount(e.Node);
}
private void OpenClientOrAccount(TreeNode Node)
{
if (Node.Tag is Client)
{
frmClients frmC = new frmClients();
Client Client = (Client)Node.Tag;
frmC.Id = Client.Id;
frmC.HouseholdId = Client.Household.Id;
frmC.MdiParent = Program.frmMain;
frmC.Show();
}
else if (Node.Tag is Account)
{
frmAccounts frmA = new frmAccounts();
Account Account = (Account)Node.Tag;
frmA.Id = Account.Id;
frmA.ClientId = Account.Client.Id;
frmA.MdiParent = Program.frmMain;
frmA.Show();
}
}
这是定义树视图的设计器代码
//
// tvClientsAccounts
//
this.tvClientsAccounts.BackColor = System.Drawing.SystemColors.Control;
this.tvClientsAccounts.Indent = 15;
this.tvClientsAccounts.LineColor = System.Drawing.Color.DarkGray;
this.tvClientsAccounts.Location = new System.Drawing.Point(228, 193);
this.tvClientsAccounts.Name = "tvClientsAccounts";
this.tvClientsAccounts.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
treeNode9});
this.tvClientsAccounts.PathSeparator = "";
this.tvClientsAccounts.ShowNodeToolTips = true;
this.tvClientsAccounts.Size = new System.Drawing.Size(411, 213);
this.tvClientsAccounts.TabIndex = 23;
this.tvClientsAccounts.BeforeExpand += new System.Windows.Forms.TreeViewCancelEventHandler(this.tvClientsAccounts_BeforeExpand);
this.tvClientsAccounts.AfterExpand += new System.Windows.Forms.TreeViewEventHandler(this.tvClientsAccounts_AfterExpand);
this.tvClientsAccounts.BeforeSelect += new System.Windows.Forms.TreeViewCancelEventHandler(this.tvClientsAccounts_BeforeSelect);
this.tvClientsAccounts.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.tvClientsAccounts_AfterSelect);
this.tvClientsAccounts.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.tvClientsAccounts_NodeMouseClick);
感谢您的帮助拉斯