JustAnotherPersonYouDontKnow JustAnotherPersonYouDontKnow - 2 months ago 19
Vb.net Question

Set focus on the application being opened?

I am opening a application from a winform. I want to focus on that application after opening. Currently when i open it, it opens behind the winform. Anyone know how to get me started? Here's how i'm opening my application from the form:

Process.Start("C:\myapplication.exe")
'set focus to that particular application or bring it in front of the winform application.

Answer

Try adding this declaration somewhere within your class:

 Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As IntPtr

...and starting the process this way:

Dim p As New System.Diagnostics.Process
p.StartInfo.FileName = "C:\myapplication.exe"
p.StartInfo.CreateNoWindow = False
p.StartInfo.WindowStyle = ProcessWindowStyle.Maximized
p.Start()
SetForegroundWindow(p.Handle)
Comments