Click here to Skip to main content
15,879,613 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I just want to focus a form which was the toplevel form.

I focused the Second form using Form.Showdialog().
Now my problem is that Second form's taskbar icon is hidden.

So Only the parent form's taskbar icon is visible.

If I click on the taskbar icon of the first form only first form is visible whereas second form is hidden.

Note: I can't focus the second form which is the toplevel form. How to fous it when first forms taskbar icon clicked.

How to get rid of this problem.
Updated 18-Jan-23 2:53am
Philippe Mori 31-Aug-15 8:53am    
Not enough information. We need to know if you create a modal or modeless form and pertinent properties of those forms...

1 solution

First of all, the problem has nothing to do with the visibility of the taskbar icon representing your form, but I understand that you are asking because you have nothing to click on. You can do it programmatically, but why?

It's a complex of problems, so I just list some things you need to care for; and you try to put it together yourself, because your problem is not clearly explained:
  • Forms are not "focused" but are activated:[^].
  • You shouldn't loose the active state of a form in a modal state, unless you switch to another application. There is no a reason to force activation of your application's form; the user knows better. If the user switches to another application, assume it's done on purpose.
  • You should better maintain the Z-order of all application forms in respect to the switching to other applications. Al you forms should come together in Z-order of the desktop. You can easily achieve it if you maintain owner-owned relationship between all forms:[^] (see also other related members, but this one would be enough).

    Practically, it would be enough to make a main form an owner of all other forms and keep the main form always visible (I don't mean it cannot be covered by other forms of your application or other applications, it can). Then, no matter of what form is on top in Z-order, when you activate any form of your application, it will move all other forms on top in some order, so none of the windows of other applications will sneak in between.
  • It's good to couple the previous technique with the use of Form.ShowInTaskbar:[^].

    The base design matching the above would be this: make this property true for your main form, false for all other forms; this way, if the user activates your application using the taskbar or not (taskbar will always show only one item per your application, the only one to click on), some of your forms will be activated, if the application is showing a modal form at this moment, the top-level modal form will be activated. That should solve your problem.

    At the same time, you can deviate from this style, intentionally adding Form.ShowInTaskbar true for some other select form, such as your modal form. I don't like this style, because it will give the user a choice what to click on, and one click would make no sense. You could also maintain the following rule: only one form at a time should have this property equal to true. But I would not bother; the simplest rule showing only the main form in the taskbar is good enough.
  • Even better, prefer the design with only one main form. What was other forms, could become some controls withing the main form, it can be panels (showing and hiding, optionally resizing), TabPage instances in an instance of TabControl, and so on. I don't mean some more modal form; you can have some small number of them, also don't overdo it. Such design is the easiest to navigate and understand. You can even develop the UI similar to Visual Studio, with dynamic docking.
  • At the same time, never use MDI. Just don't.

If you need more specific advice, you have to provide more detailed information.

Good luck.
Share this answer

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