I'm using ApplicationContext to show 2 windows of the same form. This works perfect. But now I have to show an extra dialog form inside both windows where the user can choose some settings.
When I display this dialogform with ShowDialog the focus is only in one window and the other window is frozen until I close the dialogForm. I know this is because showdialog shows the form in modal mode.
How can I avoid this behaviour and let both forms act as independent from each other? Can I do this with ApplicationContext?
Program.cs:
class MyApplicationContext : ApplicationContext
{
List<MainForm> forms = new List<MainForm>();
public MyApplicationContext(int numForms)
{
for (int i = 0; i < numForms; i++)
{
forms.Add(new MainForm(i));
}
}
void MyApplicationContext_FormClosing(object sender, FormClosingEventArgs e)
{
Application.Exit();
}
}
[STAThread]
static void Main(string[] args){
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
MyApplicationContext ac = new MyApplicationContext(2);
Application.Run(ac);
}
MainForm.cs:
public MainForm(int id)
{
InitializeComponent();
this.Invoke(new MethodInvoker(delegate ()
{
DialogForm frm = new DialogForm ();
frm.ShowDialog(this);
}));
}