Reputation: 3214
I want to open a child form that only locks its parent form. I can't use ShowDialog() because it locks all opened forms until dialog closes.
Main Form - Users Form - Services Form
When I open a new child form as Add New User on Users form, I want only lock Users form but I can also open Services form or any other form on Main Form.
Any suggestions?
Upvotes: 0
Views: 929
Reputation: 673
Borrowed an idea from How-To-Prevent-Control-From-Stealing-Focus. Basically, when you open "Add New User", disable the calling form. When "Add New User" closes, enable the calling form. I put an example below.
public partial class Form1 : Form
{
Form2 frm2;
Form3 frm3;
public override bool Focused
{
get
{
return HasFocus;
}
}
private bool HasFocus = false;
public Form1()
{
InitializeComponent();
frm3 = new Form3();
}
void frm2_FormClosed(object sender, FormClosedEventArgs e)
{
frm2.FormClosed -= frm2_FormClosed;
this.Enabled = true;
}
private void button1_Click(object sender, EventArgs e)
{
frm2 = new Form2();
frm2.FormClosed += frm2_FormClosed;
frm2.Show();
this.Enabled = false;
}
private void button2_Click(object sender, EventArgs e)
{
frm3.Show();
}
}
Upvotes: 2