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();
}
}
}