c# - 当 treenodeclick 打开表单时,表单落后

标签 c# .net vb.net

<分区>

这是我在任何站点上发布的第一个问题帖子,希望您能通过帮助我来欢迎我。我正在开发一个 vb.net Windows 应用程序,我在主窗体中使用 TreeView 作为软件菜单。我正在尝试通过按回车键或单击树节点来打开新表单。当我在 treenode 上按 enter 时一切正常,但是当我单击在主窗体后面打开的 treenode 新窗体时。请帮助我如何在主窗体前面显示新窗体(设置 TopMost 属性或 MDIParent 不适合我的应用程序)。 提前致谢

Private Sub TreeView1_NodeMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseClick
     If e.Node.Text = "Purchase" Then
          Dim frm As New frm_purchase
          frm.Show()
     End If
End Sub

Private Sub TreeView1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TreeView1.KeyDown
        If e.KeyData = Keys.Enter Then
            If TreeView1.SelectedNode.Text = "Purchase" Then
                Dim frm As New frm_purchase
                frm.Show()
            End If
        End If
End Sub 

最佳答案

.Show() 方法 has one overload以指示表单的所有者。尝试使用它而不是默认值:

Private Sub TreeView1_NodeMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseClick
 If e.Node.Text = "Purchase" Then
      Dim frm As New frm_purchase
      frm.Show(ParentForm)
 End If

ParentForm 在这种情况下,指的是您的 MDI 容器。

You can use this method to display a non-modal form. When you use this method, the Owner property of the form is set to owner. The non-modal form can use the Owner property to get information about the owning form. Calling this method is identical to setting the Owner property of the non-modal and then calling the Show() method.

关于c# - 当 treenodeclick 打开表单时,表单落后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38103799/

相关文章:

c# - 为什么接口(interface)在 IL 级别作为 "abstract interface"发出?

c# - 帮助调试 - Application_Start 何时在 global.asax 文件中运行?

c# - 测试 EF 保存更改修饰符。传入 DbPropertyValues

.net - 在方法 Y 中查找方法 X 的调用

c# - 在 C# 中可以打开的最大文件数是否有限制?

asp.net - 使用类库从 web.config/app.config 获取配置设置

c# - 在 C# 中组合多个条件表达式

c# - 从解决方案生成类依赖图的任何工具

javascript - 如何根据环境启用/禁用javascript?

vb.net - Entity Framework 一对多关系,当设置了parentID时,子对象中的父对象为空