472,340 Members | 1,816 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,340 software developers and data experts.

Modal forms

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
8 5067
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Hector | last post by:
I have a ComboBox set up in a non-modal form. When a selection is made from the ComboBox, the handler code closes the form, but then the system...
3
by: Andrew | last post by:
I get a Null Reference Exception if I close a non-modal dialog (that is, a form opened with Show()) when a selection is made from a ComboBox. The...
2
by: cassidyc | last post by:
Hi, I was wondering if anyone has come accross this issue? And if they have any solutions I have that can create new copies of itself Form1...
8
by: Stephen Rice | last post by:
Hi, I have a periodic problem which I am having a real time trying to sort. Background: An MDI VB app with a DB on SQL 2000. I have wrapped...
2
by: Mike | last post by:
Hi, I'm having a problem with modal forms on windows. I've written a very short test program, with a main window and a form called from the main...
2
by: =?Utf-8?B?TmF0aGFuIFdpZWdtYW4=?= | last post by:
Hi, I am wondering why the .NET Framework is quite different from Win32 API when it comes to displaying system modal message boxes. Consider...
11
by: VK | last post by:
In the continuation of the discussion at "Making Site Opaque -- This Strategy Feasible?" and my comment at...
2
by: diogenes | last post by:
I have created many shortcut/popup (aka context, or right-click) menus for my application - instead of toolbars or standard drop-down menus. ...
4
by: =?Utf-8?B?Z2luYWNyZXNzZQ==?= | last post by:
I am trying to close/dispose multiple instances of a form but because they are modal and hidden, they do not show up in My.Application.OpenForms. ...
1
by: Mohit | last post by:
Hi all, I am working on a windows based client server application with multiple forms. All forms are having custom title bars with no default...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.