Modeless dialog as owner of a modal dialog

  • Thread starter Thread starter hagarwal
  • Start date Start date
H

hagarwal

Hello
Can a modeless form be used as the "owner" of a modal form?

Here's the situation, from my MainForm, I have created a modeless form
using "Show" - and showed a modal form using "ShowDialog".

For some reason, if I do any user action on my modal form, it falls
behind the MainForm.

Any clues?
Thanks
Harsh
 
Can a modeless form be used as the "owner" of a modal form?
Yes.

Here's the situation, from my MainForm, I have created a
modeless form using "Show" - and showed a modal form using
"ShowDialog".

Did you use ShowDialog(this) from the parent form?
For some reason, if I do any user action on my modal form,
it falls behind the MainForm.

Can you post a short program that shows this behaviour?

Eq.
 
Paul
Thanks for the reply.

I think I figured out what the problem was - a buggy(by design maybe??)
component.

I am using this third party drop down component, that basically creates
a new form on the dropdownclick event. The component uses a strange
logic to decide its parent, and that's what was causing the problem.

However, now I am having another problem.

I think its best to describe it with code, as you suggested.

In MainForm.cs:
try
{
OutlookSynchTool tool = new
OutlookSynchTool(OutlookSynchMode.Normal);
tool.Owner = this;
tool.InitializeGrid(); // this method call does loads the grid in
the form with data
tool.TopMost = true;
tool.ShowDialog(this);
}

OutlookSynchTool is extended from System.Windows.Forms.Form.

In the OutlookSynchTool class, there is call to the second dialog:
LinkNewContactToEntityDialog linkdialog = new
LinkNewContactToEntityDialog(mContactsToLink);
linkdialog.TopMost = true;
mLinkEntityToContactDelegate = new
LinkEntityToContactDelegate(linkdialog.ShowDialog);
if (InvokeRequired)
{
linkdialog.Invoke(mLinkEntityToContactDelegate, new object[1]
{this});
}
else
{
linkdialog.ShowDialog(this);
}

OutlookSynchTool is modal to MainForm. LinkNewContactToEntityDialog is
modal to OutlookSynchTool. When the input focus is in
LinkNewContactToEntityDialog, I can still interact with the
OutlookSynchTool dialog. I reckon this should be impossible, because of
the modal-ness - but ofcourse I am wrong.

Is this too confusing? Am I missing something?

Regards
Harsh
 
Hey Paul
I have figured it out. The problem was that the second form was being
created on a worker thread inside the first form. This led to the weird
behaviour.

Moving it into a Invoke, solved the problem.
 
Back
Top