Question How to bring an already running application in front?

Developer111

Member
Joined
Apr 21, 2010
Messages
24
Programming Experience
5-10
I am developing an application having multiple screens appearing one after another using vb.net. My requirement is to bring some screens (windows form) in front of the user to take input and some of the forms can work in background (behind other applications) as they are only progress showing forms.

I tried Me.active(), Me.BringToFront(), Me.Focus(), and also some of the APIs like GetForegroundWindow(),SetForegroundWindow(), ShowWindow() etc, but failed to do so.

I tried another set of instructions
Me.TopMost = True
Me.Active()
Me.TopMost = False

Its works for me but once my form come in front, no other application can appear on top untill the my form is selected manually. Although I tried Me.Select() and Me.Focus() after above mentioned set of instructions but failed.

Can anybody help to get the solution for this problem

Thanks in Advance
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,169
Location
Sydney, Australia
Programming Experience
10+
The one and only thing you need to do is call Activate on the form. Focus should pretty much never be used. Select and BringToFront are for controls, not forms. TopMost controls whether a form is always displayed over other forms but has nothing to do with focus. If Activate is not working then there's a reason for it, because the explicit purpose of the Activate method is to make the form it's called on the active form, which means it takes focus and is displayed in front of all non-topmost windows. The only reason that I can think of offhand is that you have a modal dialogue showing.
 

Developer111

Member
Joined
Apr 21, 2010
Messages
24
Programming Experience
5-10
Thanks for reply,

On calling Activate to the form, it start blinking in the taskbar. I am using Windows XP SP3. One thing i want to share that when i m in Debug mode then Activate works prefect but on closing VS2008 and executing the program thru excutable causing the problem. Is this experienced by anyone else?

I have a Main form. Main form has a panel(panelMain) and other forms are added in this panel. The way i m showing the form is:

panelMain.Controls.Item(panelMain.Controls.IndexOf(Object_FrmToShow)).Show()
 
Top Bottom