为什么我的新表格一直移动到后面? [英] Why does my new form keep moving to the back?

查看:32
本文介绍了为什么我的新表格一直移动到后面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Visual Studio 2013 的 Visual Basic .NET

Visual Basic .NET using Visual Studio 2013

我有一个从另一个表单打开的表单,但是当我打开时,它总是在打开它的表单后面.传递到新表单的 Al 代码在 form.Show() 之前传递.

I have a form that I open from another form, but when I do, it always goes behind the form that opened it. Al code that passes to the new form, gets passed before the form.Show().

这是打开新表单的代码.

Here is the code that opens the new form.

Private Sub OpenContentWindow(strNewNavigation As String)

    Dim newContent As New FContent

    newContent.SetIETMPath(strIETMPath)
    newContent.SetIETMName(strIETMName)
    newContent.SetIETMMan(strNewNavigation)
    newContent.SetIETMIcon(strIETMIcon)
    newContent.SetPageToLaunch(strNewNavigation)
    newContent.Show()

End Sub

这是新表单中的代码.

Public Class FContent



#Region "Variables/Class Instances"

Private logger As New CDataLogger
Private pathing As New CPaths
Private annotes As New CAnnotes
Private mouser As New CMouse
Private strIETMPath As String
Private strIETMName As String
Private strIETMMan As String
Private strIETMIcon As String
Private strPageToLaunch As String

#End Region



#Region "Load Sub Routines"

' Form Load
Private Sub FContent_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    Me.Text = strIETMName
    Me.Icon = New System.Drawing.Icon(strIETMIcon)
    StartNavigation(strPageToLaunch)

End Sub

' Just pass in the file you want to view
Public Sub StartNavigation(strFileToNavigate As String)

    StartNavigation(strFileToNavigate, True)

End Sub

' Just pass in the file you want to view ( if a manual change it will load TOCs also )
Public Sub StartNavigation(strFileToNavigate As String, blnManual As Boolean)

    If blnManual Then
        wbContent.Navigate(New Uri(strIETMPath & strFileToNavigate))
        wbTOC.Navigate(New Uri(strIETMPath & strIETMMan & "\toc.html"))
        wbLOF.Navigate(New Uri(strIETMPath & strIETMMan & "\lof.html"))
        wbLOT.Navigate(New Uri(strIETMPath & strIETMMan & "\lot.html"))
        wbLOC.Navigate(New Uri(strIETMPath & strIETMMan & "\loc.html"))
    Else
        wbContent.Navigate(New Uri(strIETMPath & strFileToNavigate))
    End If

End Sub

#End Region



#Region "Set Sub Routines"

' Set IETM Path
Public Sub SetIETMPath(strNewIETM As String)

    strIETMPath = strNewIETM

End Sub

' Set IETM Name
Public Sub SetIETMName(strNewIETM As String)

    strIETMName = strNewIETM

End Sub

' Set IETM Manual
Public Sub SetIETMMan(strNewIETM As String)

    strIETMMan = strNewIETM.Substring(0, strNewIETM.IndexOf("/"))

End Sub

' Set IETM Icon
Public Sub SetIETMIcon(strNewIETM As String)

    strIETMIcon = strNewIETM

End Sub

' Set Page To Launch
Public Sub SetPageToLaunch(strNewPage As String)

    strPageToLaunch = strNewPage

End Sub

#End Region

推荐答案

确保调用表单上方显示的最简单方法是设置 Owner 被调用窗体的属性到调用窗体的实例.

The easiest way to ensure the display above the calling form is to set the Owner property of the called form to the instance of the calling form.

因此,假设此 OpenContentWindow 方法位于要创建 FContent 实例的表单的类代码中,您可以调用 显示方法将引用传递给当前表单实例

So, supposing that this OpenContentWindow method is inside the class code of the form that want to create the instance of an FContent you could call the Show method passing the reference to the current form instance

Private Sub OpenContentWindow(strNewNavigation As String)

    Dim newContent As New FContent

    newContent.SetIETMPath(strIETMPath)
    newContent.SetIETMName(strIETMName)
    newContent.SetIETMMan(strNewNavigation)
    newContent.SetIETMIcon(strIETMIcon)
    newContent.SetPageToLaunch(strNewNavigation)
    newContent.Show(Me)

End Sub

在上面的链接(MSDN)中,您可以阅读

In the link above (MSDN) you could read

当一个表单被另一个表单拥有时,它被关闭或隐藏所有者形式.例如,考虑一个名为 Form2 的表单,它属于一个名为 Form1 的表单.如果 Form1 已关闭或最小化,则 Form2 也是关闭或隐藏.拥有的表单也永远不会显示在它们的后面所有者表单.您可以为窗口使用拥有的表单,例如查找和替换窗口,当所有者窗体为被选中.要确定父窗体拥有的窗体,请使用OwnedForms 属性.

When a form is owned by another form, it is closed or hidden with the owner form. For example, consider a form named Form2 that is owned by a form named Form1. If Form1 is closed or minimized, Form2 is also closed or hidden. Owned forms are also never displayed behind their owner form. You can use owned forms for windows such as find and replace windows, which should not disappear when the owner form is selected. To determine the forms that are owned by a parent form, use the OwnedForms property.

这篇关于为什么我的新表格一直移动到后面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆