When using form.ShowDialog() a thread in mainform doesn't work
By : Hasan Priyo
Date : March 29 2020, 07:55 AM
around this issue ShowDialog() is a blocking call. The thread actually runs, it is busy pumping the message loop for the dialog. This is no different from what happens on the main thread of your program. Doing this is very unwise, the dialog has no Z-order relationship with the rest of the windows in your app. One classic mishap is that it can disappear behind another window but no good way for the user to find it back. Use Control.BeginInvoke to create the dialog on the UI thread instead. This also ensures that your thread keeps 'running'.
|
accessing variable like this MainForm.property , without instantiating MainForm mf = new MainForm;
By : FrederikK
Date : March 29 2020, 07:55 AM
help you fix your problem Two options: Pass a reference of MainForm to Form2 and access it from there. Make the property static on MainForm.
|
How can I close the MainForm, without closing the others?
By : Trafton Kenney
Date : March 29 2020, 07:55 AM
may help you . If you want a basic form that will pretty much just allow the user to play until they close the other form then close this form, use this: code :
private void button2_Click(object sender, EventArgs e)
{
Form f2 = new Form1();
this.Hide();
f2.ShowDialog();
this.Close();
}
private void button2_Click(object sender, EventArgs e)
{
Form f2 = new Form1();
this.Hide();
if(f2.ShowDialog() == DialogResult.OK)
{
this.Show();
}
else
{
this.Close();
}
}
|
How to close a form and come back to mainform
By : Olga Epshteyn
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , You actually do not need to call form3 from form1 just to pass a value. If I understand you correctly, the desired flow should be like this code :
form1
opens
form2
opens
form3
|
| value
|
form1 <---+
public string ValueFromForm3
{
get;
private set;
}
public void ShowForm3()
{
using (Form3 f3 = new Form3())
{
if (f3.ShowDialog(this) == DialogResult.OK)
ValueFromForm3 = f3.TheValueYouNeed;
}
}
public void ShowForm2()
{
using (Form2 f2 = new Form2())
{
if (f2.ShowDialog(this) == DialogResult.OK)
DoSomethingWith(f2.ValueFromForm3);
}
}
|
mainform trying to show on closing the login form
By : sfik
Date : March 29 2020, 07:55 AM
I hope this helps you . Instead of hiding Main Form before you show Login you should use initialize Application to start with Main Form hidden. To do that just add Application.ShowMainForm := false before you create main form. Application.Run that executes after you close your login form will show or not show Main Form based on value of Application.ShowMainForm variable that is by default true. So that will introduce flicker because main form will be shown before application terminates. code :
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.ShowMainForm := false;
Application.CreateForm(TForm1, Form1);
Login;
Application.Run;
end.
|