C # Windows Forms, do not display the form on the taskbar, but force it to move forward when the form that is shown there is focused

I am creating an application that will have a Photoshop-like interface, with several separate shapes helping to edit the object. So, I will have several forms, one of which is the "main" (provides a file menu, settings menu, etc.), and the others have controls that edit the object opened in the main form.

Let's say for the sake of simplicity this is a text editor and I have a MainForm and a StyleForm. Now I need the whole application to appear as one "bar" on the Windows taskbar. This can be achieved by setting ShowInTaskbar to false for the StyleForm, but if I, say, focus on another application, then focus my application, only the MainForm will get on top of other windows, the StyleForm will remain hidden under the application window I previously did.

I found the answer here Make all program related forms first when one form is selected , but it imports the dll. Perhaps there is a .net solution for this?

Also, I would like to display something else in the taskbar, not the MainForm signature, is that possible?

+3


source to share


2 answers


I set the second form to ShowInTaskBar = false

, set FormBorderStyle

to SizableToolWindow

, and then created it using the following code:

public partial class Form1 : Form
{
    Form2 f2;

    public Form1()
    {
        InitializeComponent();

        f2 = new Form2();
        f2.Owner = this;  // <-- This is the important thing
        f2.Show();
    }
}

      



This makes the subformat F2

stay on top Form1

and hides and shows it when it Form1

is hidden and shown.

EDIT
Oh, I used Visual Studio 2010 and .NET 4 Client Profile if that matters. However, this should work with other versions.

+11


source


In the main window you can catch the Focus event and then for each subform call the BringToFront method



0


source







All Articles