How to show form in front in C#

c# bring another application to front
c# bring window to front
c# show form
how to open another form in c#
c# bring child form to front
show form 2 c#
c# send window to front
c# focus window


Please does anyone know how to show a Form from an otherwise invisible application, and have it get the focus (i.e. appear on top of other windows)? I'm working in C# .NET 3.5.

I suspect I've taken "completely the wrong approach"... I do not Application.Run(new TheForm ()) instead I (new TheForm()).ShowModal()... The Form is basically a modal dialogue, with a few check-boxes; a text-box, and OK and Cancel Buttons. The user ticks a checkbox and types in a description (or whatever) then presses OK, the form disappears and the process reads the user-input from the Form, Disposes it, and continues processing.

This works, except when the form is show it doesn't get the focus, instead it appears behind the "host" application, until you click on it in the taskbar (or whatever). This is a most annoying behaviour, which I predict will cause many "support calls", and the existing VB6 version doesn't have this problem, so I'm going backwards in usability... and users won't accept that (and nor should they).

So... I'm starting to think I need to rethink the whole shebang... I should show the form up front, as a "normal application" and attach the remainer of the processing to the OK-button-click event. It should work, But that will take time which I don't have (I'm already over time/budget)... so first I really need to try to make the current approach work... even by quick-and-dirty methods.

So please does anyone know how to "force" a .NET 3.5 Form (by fair means or fowl) to get the focus? I'm thinking "magic" windows API calls (I know

Twilight Zone: This only appears to be an issue at work, we're I'm using Visual Studio 2008 on Windows XP SP3... I've just failed to reproduce the problem with an SSCCE (see below) at home on Visual C# 2008 on Vista Ulimate... This works fine. Huh? WTF?

Also, I'd swear that at work yesterday showed the form when I ran the EXE, but not when F5'ed (or Ctrl-F5'ed) straight from the IDE (which I just put up with)... At home the form shows fine either way. Totaly confusterpating!

It may or may not be relevant, but Visual Studio crashed-and-burned this morning when the project was running in debug mode and editing the code "on the fly"... it got stuck what I presumed was an endless loop of error messages. The error message was something about "can't debug this project because it is not the current project, or something... So I just killed it off with process explorer. It started up again fine, and even offered to recover the "lost" file, an offer which I accepted.

using System;
using System.Windows.Forms;

namespace ShowFormOnTop {
    static class Program {
        static void Main() {
            //Application.Run(new Form1());
            Form1 frm = new Form1();

Background: I'm porting an existing VB6 implementation to .NET... It's a "plugin" for a "client" GIS application called MapInfo. The existing client "worked invisibly" and my instructions are "to keep the new version as close as possible to the old version", which works well enough (after years of patching); it's just written in an unsupported language, so we need to port it.

About me: I'm pretty much a noob to C# and .NET generally, though I've got a bottoms wiping certificate, I have been a professional programmer for 10 years; So I sort of "know some stuff".

Any insights would be most welcome... and Thank you all for taking the time to read this far. Consiseness isn't (apparently) my forte.

Cheers. Keith.


yourForm.TopMost = true;

How to bring a Windows Form on top?, How to show form in front in C# (11 answers) Normal; } //Keeps the current topmost status of form bool top = TopMost; //Brings the to top TopMost = true; //​Set form's topmost status back to whatever it was TopMost = top; } }. This is what I use to bring an open form that is part of my application to the front. You can even use it with a button. But the form needs to be open or the application will break. "YourOpenForm" has to be the name of your form from the properties window.

There's an overload of Form.ShowDialog() which takes an IWin32Window object. That IWin32Window is treated as the parent window for the form.

If you have the parent window as a System.Windows.Forms.Form, go ahead and just pass it. If not, get the HWND (maybe by P/Invoking to FindWindow()), and create a dummy IWin32Window implementation that just returns the HWND (More details).

In C# Windows Forms Application, how to bring a form to front?, In C# Windows Forms Application, how to bring a form to front? When the user has the program minimized and presses F3 a global hook keys gets the press and translation window should be made and brought to front. Begin by starting Visual Studio and creating a new Windows Form Application project called CSharpShowForm. Visual Studio will prime the new project with a single form. Click on the Form to select it and, using the Properties panel change the Name of the form to mainForm. Next we need to add a second form.

Form.Activate() worked in my case.

C# bring Windows Form to front - MSDN, Keeping a C# Form Always on Top , how to make C# application always on top. Control.BringToFront will bring a control to the front of the hosting control, for example you might bring a TextBox in front of a Label to make sure that the label's whitespace does not obscure part of the TextBox.

  1. You said that it works fine when you use Application.Run. Why don't you want to use Application.Run, then?
  2. Have you tried calling BringToFront() from OnLoad or OnShown?

Keep Form on Top of All Other Windows, C# Windows Forms Application Each time you create a Windows application, Visual Studio will display a default blank form, onto which you can drag the  Step 2: Add a new form Now go to Solution Explorer and select your project and right-click on it and select a new Windows Forms form and provide the name for it as form2.

This is the final solution I wrote after 20 different attempts:

/* A workaround for showing a form on the foreground and with focus,
 * even if it is run by a process other than the main one
public static void ShowInForeground(this Form form, bool showDialog = false)
    if (showDialog)
        //it's an hack, thanks to
        form.WindowState = FormWindowState.Minimized;
        form.Shown += delegate(Object sender, EventArgs e) {
            ((Form)sender).WindowState = FormWindowState.Normal;
        //it's an hack, thanks to
        form.WindowState = FormWindowState.Minimized;
        form.WindowState = FormWindowState.Normal;

        //set focus on the first control
        form.SelectNextControl(form.ActiveControl, true, true, true, true);

How to Create a C# Windows Forms Application, how to keep windows form top of all other forms in c#.Duration: 4:31 Posted: Aug 2, 2016 CalledForm.Owner = CallerForm; CalledForm.Show(); This will show the 'child' form without it stealing focus. The child form will also stay on top of its parent even if the parent is activated or focused. This code only works easily if you've created an instance of the child form from within the owner form.

How Keep Windows form allways on top other forms, Before that I will explain group boxes and picture boxes in Windows Forms. Step 1: Login form. There is a login from when I enter a password and  How to use panel control to create multiple pages in c#. This is the best way to learn c# for beginners.

How to Open a Second Form Using First Form in , Writing C# Code to Display a Non-Modal Form. We are going to use the button  how to keep windows form top of all other forms in c#. how to keep windows form top of all other forms in c#. Show more Show less. Loading

Hiding and Showing Forms in C Sharp, Net - Forms - Let's start with creating a Window Forms Application by following the following steps Brings the control to the front of the z-order. Show. Displays the control to the user. 22. ShowDialog. Shows the form as a modal dialog box. Keep Form on Top of All Other Windows The System.Windows.Forms namespace contains classes for creating Windows-based applications that take full advantage of the rich user interface features available in the Microsoft Windows operating system.