473,385 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 5151
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 crashes because of an unhandled NullReferenceException....
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 error message refers to Unsafe Native Methods, but...
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 as = new form1(); af.show(); This form can also...
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 all the DB access into an object which spawns a...
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 window. The form is set to modal with...
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 the four following types of system modal message...
11
by: VK | last post by:
In the continuation of the discussion at "Making Site Opaque -- This Strategy Feasible?" and my comment at http://groups.google.com/group/comp.lang.javascript/msg/b515a4408680e8e2 I have...
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. Within my custom menu, I am using...
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. They must be modal, so making them modeless is not...
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 bars. There is one main form. Some forms are opened up...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.