Modal forms

G

Guest

I want to have 3 forms open modally. They are 1: a background form (bgform);
2: form_x; 3: loginform. bgform is always open. form_x could be any random
form that that bgform has shown modally. Whenever, the pc is idle for x
minutes then loginform is displayed. This all works fine, except that
loginform does not seem to be a child of form_x. Hence I am able to interact
with form_x. I want the focus to be on loginform until it is closed. here is
my code.


public partial class bgform : Form
{
private void someFunction (......)
{
Form_x form_x = new Form_x();
form_x.ShowDialog();
................
//loginform is activated by idle time
LoginForm loginForm = new LoginForm();
loginForm.ShowDialog();
loginForm.TopMost = true;
loginForm.Parent = form_x;
.................
.................
}
}


//currentForm.Visible = false;

loginForm.ShowDialog();
loginForm.Parent = currentForm;
loginForm.TopMost = true;

//MessageBox.Show(currentForm.Name);
}
 
N

Nicholas Paldino [.NET/C# MVP]

Dave,

You need to call the overload of the ShowDialog method which takes an
IWin32Window interface implementation. This is implemented by the Control
class, which Form derives from, so you can just pass that. You want to pass
the form, or a control on the form which you want to be the parent.
 
G

Guest

I tried the following below and nothing happened

loginForm.ShowDialog(form_x);

Is it correct?
--
L. A. Jones


Nicholas Paldino said:
Dave,

You need to call the overload of the ShowDialog method which takes an
IWin32Window interface implementation. This is implemented by the Control
class, which Form derives from, so you can just pass that. You want to pass
the form, or a control on the form which you want to be the parent.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Dave said:
I want to have 3 forms open modally. They are 1: a background form
(bgform);
2: form_x; 3: loginform. bgform is always open. form_x could be any random
form that that bgform has shown modally. Whenever, the pc is idle for x
minutes then loginform is displayed. This all works fine, except that
loginform does not seem to be a child of form_x. Hence I am able to
interact
with form_x. I want the focus to be on loginform until it is closed. here
is
my code.


public partial class bgform : Form
{
private void someFunction (......)
{
Form_x form_x = new Form_x();
form_x.ShowDialog();
................
//loginform is activated by idle time
LoginForm loginForm = new LoginForm();
loginForm.ShowDialog();
loginForm.TopMost = true;
loginForm.Parent = form_x;
.................
.................
}
}


//currentForm.Visible = false;

loginForm.ShowDialog();
loginForm.Parent = currentForm;
loginForm.TopMost = true;

//MessageBox.Show(currentForm.Name);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top