views:

467

answers:

1

I have two forms for my application, that are visible in the Windows taskbar. When a modal dialog is popped up on the main form, the secondary form is locked. However, when the user clicks on the secondary form on the taskbar, it appears over the modal dialog box, and is basically frozen.

Is there a way to ensure that the modal dialog box does not draw underneath the secondary form? The topmost property is no good, since this draws on top of everything, even stuff not related to the application.

+1  A: 

Your problem may be that you haven't specified an owner for the dialog:

Owned windows typically don’t need their own representation on the Windows taskbar because they are subordinate to their owners. Because activating an owned window implicitly activates the owner and vice versa, it would merely clutter up the taskbar to have entries for both. So owned forms normally have their ShowInTaskBar properties set to false.

The following code fragments (in VB and C#) show a new form being created, owned, and displayed:

// defining an owner form in C#

MyForm ownedForm = new MyForm();

ownedForm.ShowInTaskbar = false;

AddOwnedForm(ownedForm);

ownedForm.Show();

In your case, it would appear that you need to set the owner window for the dialog. That would prevent the window that is presenting the dialog from appearing over it.

EDIT Should have cited my source: .NET Windows Forms in a Nutshell. Also, I omitted the VB.NET code. I have appropriately flogged myself, but don't feel like wading through the PDF file to track it down.

Mike Hofer
I love you man. You resolved a major issue for our app group :)Kudos.
Jon