Click here to Skip to main content
15,900,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys,

Every time my application opens a new form, a new icon is created on the Windows taskbar. Normally, a Windows application only shows the application icon on the taskbar; not an icon for each form. I've never seen anything like this. How do I fix it?

I'm using VS 2010.

Thanks...
Posted

You are right, showing new icons for each form of application is wrong. You need to use
C#
Form newForm = //...
newForm.ShowInTaskbar = false; //this is what you are asking about

//bonus:
newForm.Owner = myMainForm;
//if this is done in the class of main form, will be:
//newForm.Owner = this;


Bonus: owner/owned form is another important relationship which is related to showing of the form — its activation; it will support application integrity. You should use ShowInTaskbar = true for you main form, only for this one. When you activate this form, other forms will also go on top of Z-order, so no form of other application can be placed in between.

Another way of setting up ownership is Form.AddOwnedForm.

See http://msdn.microsoft.com/en-us/library/system.windows.forms.form.aspx[^].

—SA
 
Share this answer
 
Comments
Sander Rossel 24-Oct-11 15:46pm    
My 5 for a good answer, although I still don't see the big difference with MDI...
Sergey Alexandrovich Kryukov 24-Oct-11 15:48pm    
Thank you, Naerling. There is a big difference. And OP question is not about MDI.
--SA
Sander Rossel 24-Oct-11 16:19pm    
He did not ask about it specifically. I just assumed this is what the OP was looking for. Your answer does seem to fit his question better. Although the OP never explicitly said he did NOT want to use MDI's either ;)
Steve Harp 24-Oct-11 16:32pm    
Excellent answer and thanks very much. I find it amazing that, in order to get normal Windows behavior, I have to set an additional property. Go figure...
Sergey Alexandrovich Kryukov 24-Oct-11 16:38pm    
You are welcome.

I agree, what I describe is "normal" Windows behavior. So, why API is just a bit cryptic? I guess, this is because Forms are designed the way that there is no difference between main form and others. Main form is just defined by a parameter passed to Application.Run. So, to work with other forms, you need to do minor manual adjustments...
Also, Forms library is best designed to have just one form and put what you had in other forms into containers of main form. The easiest would be tab interface with TabControl, but there can be different designs (see my comment to the answer by Naerling).

Good luck, call again.
--SA
You should create an MDI Main Form[^] as main window. All other Forms should be opened as a child of this MDI parent.
That way you'll only see your MDI in the taskbar and not all other Forms.
C#
MyForm frm = new MyForm();
frm.MdiParent = this; // If you are opening it from you main form.
frm.Show(); // Will now open as mdi child without creating a taskbar item.

Hope it helps :)
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 24-Oct-11 15:28pm    
Sorry, absolutely unrelated post. Also, MDI is highly discouraged even by Microsoft; I don't wish anyone to get into it. I just had to vote 1.
OP posted a real problem; I provided correct advice to solve it.
--SA
Sander Rossel 24-Oct-11 15:44pm    
MDI discouraged by MS? That's why everyone uses/d it? Opening forms in an MDI certainly does not show icons in the taskbar. MDI may not be all that populair anymore with all the new metro style and all, but I certainly haven't heard it's not done to use it... Especially in a WinForm app...
I've been using it for quite a while and never had problems with it.
Sergey Alexandrovich Kryukov 24-Oct-11 15:50pm    
Almost nobody uses MDI, only some... Did you ever see any good or at least professional MDI application? It works, yes, but so inconvenient. For your own sake, don't scare off your users, nobody wants to use it. It was wrong from the very beginning.
--SA
Sander Rossel 24-Oct-11 16:17pm    
Yes, I have seen professional looking and working MDI applications. It's just what the programmer makes of it. And of course the purpose of the application. For some applications it would not make sense. Clients in my line of business seem to like it just fine.
Sergey Alexandrovich Kryukov 24-Oct-11 15:53pm    
By the way, by saying "Opening forms in an MDI certainly does not show icons in the taskbar" you confirm that OP's problem is not related to MDI. If the issue exists, it means it wasn't MDI. By the way, SDI with multiple forms is also not so good. Best solution is maybe one single form with container controls in it, such as tab interface, docking interface like in Visual Studio (no, this is not MDI) and more...
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900