Nishan
Nishan

Reputation: 2871

Application not visible in taskbar when using Application.Run()

I am creating a windows application using C#.Net. I am showing a form when starting an application using below code :

Form myForm = new MyForm();
Application.Run(myForm);

Application is not appearing in taskbar, but I know its running since I can navigate to the application window using Alt-TAB.

If I use myForm.ShowDialog(), application is visible in taskbar.

What am I missing here?

UPDATE: ShowInTaskbar property is set to true for the form. UPDATE2: FormBorderStyle is set to None

Upvotes: 1

Views: 3832

Answers (4)

darkbit
darkbit

Reputation: 41

With .NET Framework 4.6.1, toggling:

this.ShowInTaskBar = false;
this.ShowInTaskBar = true;

causes FormClosing event being fired.

Calling this.Activate() in Shown event works properly.

In my case it was nonmodal form, called to be shown with ShowDialog(), but the request to create and show the form was sent from pipe. When executed by user's click on main form, everything was ok, form was shown and appeared on the taskbar.

Upvotes: 1

fiduce
fiduce

Reputation: 101

You may not set an empty string as windows title during Form load. This is what happened to me today (my window title is retrieved from a file that was missing, and so the window disappeared from the taskbar).

Upvotes: 0

Martin.Martinsson
Martin.Martinsson

Reputation: 2154

Add Activate() in Form_Shown event.

Upvotes: 1

Pilouk
Pilouk

Reputation: 1307

Toggle ShowInTaskbar in your form load event with these two lines:

This.ShowInTaskbar = False
This.ShowInTaskbar = True

It worked for me.

Upvotes: 5

Related Questions