By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,714 Members | 1,318 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,714 IT Pros & Developers. It's quick & easy.

Modal forms

P: n/a
Is this possible? I have 3 forms frmGrandparent, frmParent & frmChild. Can
frmGrandparent do a frmParent.ShowDialog() and then (while frmParent is open)
do a frmChild.ShowDialog(). At the end of the day frmChild should be the
topmost form and the focus should be on it.
--
L. A. Jones
Nov 7 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
On 2007-11-06 18:36:02 -0800, Dave <Da**@discussions.microsoft.comsaid:
Is this possible? I have 3 forms frmGrandparent, frmParent & frmChild. Can
frmGrandparent do a frmParent.ShowDialog() and then (while frmParent is open)
do a frmChild.ShowDialog(). At the end of the day frmChild should be the
topmost form and the focus should be on it.
The dialogs don't care in which class the code that shows the dialog
is. So sure, you can write code in your "frmGrandparent" class that
shows the "fmrChild" dialog.

Pete

Nov 7 '07 #2

P: n/a
Not normally. ShowDialog is blocking, so frmGrandparent will be blocked
waiting for frmParent to close, so it can't call frmChild.ShowDialog().

frmParent could call frmChild.ShowDialog()...

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
"Dave" wrote:
Is this possible? I have 3 forms frmGrandparent, frmParent & frmChild. Can
frmGrandparent do a frmParent.ShowDialog() and then (while frmParent is open)
do a frmChild.ShowDialog(). At the end of the day frmChild should be the
topmost form and the focus should be on it.
--
L. A. Jones
Nov 7 '07 #3

P: n/a
I did that but I was still able to access frmParent and frmChild dialogs
simultaneously. Do I need to explicitly specify that frmParent is the parent
of frmChild?
--
L. A. Jones
"Peter Duniho" wrote:
On 2007-11-06 18:36:02 -0800, Dave <Da**@discussions.microsoft.comsaid:
Is this possible? I have 3 forms frmGrandparent, frmParent & frmChild. Can
frmGrandparent do a frmParent.ShowDialog() and then (while frmParent is open)
do a frmChild.ShowDialog(). At the end of the day frmChild should be the
topmost form and the focus should be on it.

The dialogs don't care in which class the code that shows the dialog
is. So sure, you can write code in your "frmGrandparent" class that
shows the "fmrChild" dialog.

Pete

Nov 7 '07 #4

P: n/a
Let me explain the situation in detail. frmGrandparent is my main form.
frmParent is one of several data entry forms. frmChild is a login form. When
the computer is idle for a period of time then frmChild (login form) should
be displayed and it should have focus. I did not want to go into all the
frmParent (data entry forms) to write code to open my frmChild (login form)
after a timeout. I wanted to do it from frmGranparent (main form). But it
seems to be impossible.
--
L. A. Jones
"Peter Ritchie [C# MVP]" wrote:
Not normally. ShowDialog is blocking, so frmGrandparent will be blocked
waiting for frmParent to close, so it can't call frmChild.ShowDialog().

frmParent could call frmChild.ShowDialog()...

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
"Dave" wrote:
Is this possible? I have 3 forms frmGrandparent, frmParent & frmChild. Can
frmGrandparent do a frmParent.ShowDialog() and then (while frmParent is open)
do a frmChild.ShowDialog(). At the end of the day frmChild should be the
topmost form and the focus should be on it.
--
L. A. Jones
Nov 7 '07 #5

P: n/a
On 2007-11-06 19:11:00 -0800, Dave <Da**@discussions.microsoft.comsaid:
I did that but I was still able to access frmParent and frmChild dialogs
simultaneously. Do I need to explicitly specify that frmParent is the parent
of frmChild?
Well, what happens when you do that?

Nov 7 '07 #6

P: n/a
On 2007-11-06 19:27:01 -0800, Dave <Da**@discussions.microsoft.comsaid:
Let me explain the situation in detail. frmGrandparent is my main form.
frmParent is one of several data entry forms. frmChild is a login form. When
the computer is idle for a period of time then frmChild (login form) should
be displayed and it should have focus. I did not want to go into all the
frmParent (data entry forms) to write code to open my frmChild (login form)
after a timeout. I wanted to do it from frmGranparent (main form). But it
seems to be impossible.
It's not impossible. It works fine. You don't have to do anything
special, and you don't even need to specify a parent when you show the
dialog.

If you are having trouble, it's because you're doing something _more_
than what is necessary and which is messing things up.

I just tested this myself to be sure, two different ways:

1) second dialog shown by a button on first dialog
2) second dialog shown when a timer created in the main form expires

In both cases, the most-recently shown dialog is the only one that
accepts input.

You should post a concise-but-complete sample of code that demonstrates
how _you're_ trying to do it, and which reliably fails to accomplish
what you want it to.

Pete

p.s. Here's the "interesting" excerpt of the test code I wrote, the
custom portion of the main form class. It doesn't include any of the
Designer-generated code, nor the custom code in DialogA and DialogB
since the implementation of both of those forms isn't relevant (they
could be completely empty as far as this code cares).

The main form has a single button, to which is attached the
button1_Click method. That method starts a 2-second timer, and then
shows the first dialog. When the timer expires, the second dialog is
shown. Once the second dialog is shown, it alone accepts user input:
using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace TestNestedDialog

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

DialogA dlga = new DialogA();

Timer timer = new Timer();

timer.Tick += HandleTick;

timer.Interval = 2000;

timer.Start();

dlga.ShowDialog();

}

private void HandleTick(object sender, EventArgs e)

{

DialogB dlgb = new DialogB();

Timer timer = (Timer)sender;

timer.Stop();

dlgb.ShowDialog();

}

}

}

Nov 7 '07 #7

P: n/a
How are you testing for idle? If you're using a timer click on
frmGrandparent, you could simply call frmChild.ShowDialog(). I don't know if
that would mean frmParent would be inaccessible until frmChild is closed--I
would imagine not.

You'll likely have to implement frmParent as non-modal and fake modality by
disabling the other forms...

I'm not sure what the point of doing this is though. Are you attempting to
introduce tighter security than the computer currently has configured? If
there is a need for security of this nature it is usually domain-wide;
meaning it's a domain policy. If it isn't a domain policy there isn't a need
for security of that nature, which means the added security to the
application is still operating in a lower-security environment. i.e. if
security of this nature is important, its important for the entire computer.

Also, users hate having to re-authenticate themselves when they've already
been authenticated. If there is a password-protected screensaver running
they'll have to authenticate themselves there then again in your application.

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
"Dave" wrote:
Let me explain the situation in detail. frmGrandparent is my main form.
frmParent is one of several data entry forms. frmChild is a login form. When
the computer is idle for a period of time then frmChild (login form) should
be displayed and it should have focus. I did not want to go into all the
frmParent (data entry forms) to write code to open my frmChild (login form)
after a timeout. I wanted to do it from frmGranparent (main form). But it
seems to be impossible.
--
L. A. Jones
"Peter Ritchie [C# MVP]" wrote:
Not normally. ShowDialog is blocking, so frmGrandparent will be blocked
waiting for frmParent to close, so it can't call frmChild.ShowDialog().

frmParent could call frmChild.ShowDialog()...

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
"Dave" wrote:
Is this possible? I have 3 forms frmGrandparent, frmParent & frmChild. Can
frmGrandparent do a frmParent.ShowDialog() and then (while frmParent is open)
do a frmChild.ShowDialog(). At the end of the day frmChild should be the
topmost form and the focus should be on it.
--
L. A. Jones
Nov 7 '07 #8

P: n/a
On 2007-11-06 20:01:00 -0800, Peter Ritchie [C# MVP]
<PR****@newsgroups.nospamsaid:
How are you testing for idle? If you're using a timer click on
frmGrandparent, you could simply call frmChild.ShowDialog(). I don't know if
that would mean frmParent would be inaccessible until frmChild is closed--I
would imagine not.
In the simple case (e.g. the test code I wrote to make sure I wasn't
misremembering things), the only form that accepts input is the one
most recently shown with ShowDialog().
You'll likely have to implement frmParent as non-modal and fake modality by
disabling the other forms...
Nope. Works fine, no need to do funny tricks.

I completely agree with your other comments about whether this feature
is really necessary. But my experience has been that people don't
usually want to hear that the UI they designed needs fixing, even when
it's true; they're already set on doing it a particular way.

There is also the very small possibility that this is the rare scenario
where such a UI makes sense. I have seen kiosk-style applications
where the developer doesn't want a Windows authentication presented,
ever, but they do want to manage _some_ sort of authentication. Until
Windows provides a complete kiosk management API, I think developers
are stuck doing this sort of thing.

But it's not true that Windows makes it difficult. It works just fine,
assuming one isn't doing something weird.

Pete

Nov 7 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.