使用Visual Studio 2013的Visual Basic .NET
我有一个表单,我从另一个表单打开,但是当我这样做时,它总是落后于打开它的表单。传递给新表单的Al代码在form.Show()之前传递。
以下是打开新表单的代码。
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
答案 0 :(得分:1)
确保在调用表单上方显示的最简单方法是将被调用表单的Owner属性设置为调用表单的实例。
因此,假设此OpenContentWindow
方法位于要创建FContent
实例的表单的类代码中,您可以调用Show方法将引用传递给当前表单实例
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)中,您可以阅读
当表单由另一个表单拥有时,它将被关闭或隐藏 业主表格。例如,考虑一个名为Form2的表单 一个名为Form1的表单。如果Form1关闭或最小化,Form2也是 关闭或隐藏。 拥有的表单也永远不会显示在他们的后面 所有者表单。您可以使用自有窗体,例如find和 替换窗口,当所有者表单是时,窗口不应该消失 选择。要确定父表单拥有的表单,请使用 OwnedForms属性。
答案 1 :(得分:1)
你在newContent.Show()或newContent.TopMost = true之后尝试过“newContent.BringToFront()”吗?