Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / July 2006

Tip: Looking for answers? Try searching our database.

Modal Windows & Parents

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
cj_junktrap@mail.com - 31 Jul 2006 09:28 GMT
Is it possible to have form.ShowDialog() be modal only to its
parent/owner form, and allow the user to still use any other forms in
the app?  I've tried passing the parent form in as the parameter to
form.ShowDialog, but that doesn't seem to make any difference.
Dave Sexton - 31 Jul 2006 11:35 GMT
Hi,

I'm not sure if that's possible using a built-in solution but you could just create a tight coupling between the two forms and when
the parent form is activated, check a variable to see if the child form is visible and if so activate the child form.

... Out of curiosity I just tested my suggestion and it worked as expected, however the ParentForm appears and behaves a bit strange
while the DialogForm is shown.  For one thing the XP hover styles of buttons, for instance, are active.  Another thing is that the
border chrome is always in the inactive state but you can move the Form.  Might need some elbow grease for that one but I can't
imagine that being a big issue.

The minimize, maximize, close and system buttons are all unclickable, which is desired.  Also, you can't activate any controls or
click buttons while the DialogForm is visible, which is the point, of course.  Here's the partial code:

class ParentForm : Form
{
 private readonly DialogForm dialogForm;

 public ParentForm()
 {
  InitializeComponent();

  dialogForm = new DialogForm();
  dialogForm.Owner = this;
 }

 private void btnShowDialog_Click(object sender, EventArgs e)
 {
  dialogForm.Show();
 }

 protected override void OnActivated(EventArgs e)
 {
  if (dialogForm.Visible)
 {
   SystemSounds.Beep.Play();  // lol
   dialogForm.Activate();
 }

  base.OnActivated(e);
 }

  protected override void OnClosed(EventArgs e)
 {
   dialogForm.Dispose();
   base.OnClose(e);
 }
}

Signature

Dave Sexton

> Is it possible to have form.ShowDialog() be modal only to its
> parent/owner form, and allow the user to still use any other forms in
> the app?  I've tried passing the parent form in as the parameter to
> form.ShowDialog, but that doesn't seem to make any difference.
cj_junktrap@mail.com - 31 Jul 2006 16:18 GMT
Unfortunately I can't have such tight coupling between the forms...
what I'm currently doing is setting the parent form's enabled property
to false, spinning off a new thread, calling form.ShowDialog on that
thread, and then waiting in the original thread using a sleep/DoEvents
loop until the new thread finishes (i.e. the dialog is closed) and
setting the parent's enabled property back to true.  It's messy, and I
don't like the DoEvents loop at all, but I don't really see much
alternative.

> Hi,
>
[quoted text clipped - 51 lines]
> > the app?  I've tried passing the parent form in as the parameter to
> > form.ShowDialog, but that doesn't seem to make any difference.
Dave Sexton - 31 Jul 2006 22:44 GMT
Hi,

Try creating an object to handle the 'coupling' of two forms if you can't modify the forms themselves.  Maybe create a class named,
"FormDialogRelationManager", which knows how to display a given form as a modal dialog for another given form.  You could then use
the code I supplied to manage the relation in a method named, for instance, "ShowDialog".  If that fits into your architecture it
might be easier to manage, test and document.

HTH

Signature

Dave Sexton

> Unfortunately I can't have such tight coupling between the forms...
> what I'm currently doing is setting the parent form's enabled property
[quoted text clipped - 63 lines]
>> > the app?  I've tried passing the parent form in as the parameter to
>> > form.ShowDialog, but that doesn't seem to make any difference.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.