[英]Bring Windows Forms window back to front after opening an external application
我從我的 VB.net Windows Forms 應用程序打開 ZBCD1B68617759B1DFCFF0403A6B:
Try
Process.Start(fileName)
Catch e As System.ComponentModel.Win32Exception 'no PDF viewer installed, use browser
Dim startinfo As New ProcessStartInfo
startinfo.FileName = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
startinfo.Arguments = String.Format(fileName)
startinfo.UseShellExecute = False
Process.Start(startinfo)
End Try
我希望我的申請表在 PDF 打開后回到前面。 我已經嘗試了所有這些,但都不起作用:
Me.Activate()
Me.BringToFront()
Me.TopMost = True
Me.TopMost = False
僅使用 Me.TopMost=True 實際上有效,但我不想強制我的應用程序出現在所有其他 windows 之前。 我只想在 PDF 打開后把它帶到前面一次。 一旦我添加命令 Me.TopMost = False 來重置它,它就不再起作用了。
我不知道您是否可以使用特定的 API 來執行您的要求,但從我的角度來看,您已經找到了解決方案:
Me.TopMost = True
Me.TopMost = False
您必須在 PDF 打開操作結束后立即使用這兩行。
這是使用以下代碼的示例:
Imports System.Threading
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.BackColor = Color.Green
Label1.Text = "Start"
End Sub
Private Sub PdfOperation_Simulation(sender As Object, e As MouseEventArgs) Handles Label1.MouseDown
Me.BackColor = Color.Red
Label1.Text = "Wait..."
Me.Refresh()
Thread.Sleep(3000) 'Pdf opening... I manually bring to front VisualStudio
Me.TopMost = True
Me.TopMost = False
Me.BackColor = Color.Green
Label1.Text = "Finish"
End Sub
End Class
Output:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.