I have a program that content two form the first form is the main form and is the form that the program will start form it and the second form is the form that will show one time only to take to values and then will comeback to the first and the second will close note :in the start the program will do one from two
- show second form if the values not in the program , then close the second and go to the first.
- show the first and counties on it if the program have the values .
Note: when the second form will appear the first form will be hide , then after program takes the values from the user the second form will close and the first form will show
in anther word if the user give to the program the values from before the second form will not appear ,just the first form will appear only
the problem is the second form still open when the first form open after second form took the values
Code form 1
private void Form1_Load(object sender, EventArgs e)
{
b();
}
private void b()
{
Open();
String SqlQuery = "SELECT * from test1";
DataTable dt = new DataTable();
dt = fetchData(SqlQuery);
if (!(dt.Rows.Count >0))
{
MessageBox.Show("incorect user");
fm2 = new Form2();
fm2.Show();
this.Hide();
}
}
code form2
public void fn()
{
String SqlQuery = "SELECT * from test1 ";
DataTable dt = new DataTable();
dt = fetchData(SqlQuery);
if (dt.Rows.Count > 0)
{
Application.OpenForms[0].Show();
MessageBox.Show("DONE");
this.Close();
}
}
private void button1_Click(object sender, EventArgs e)
{
string insertQuery = "INSERT INTO test1( name, phone) VALUES" +
"('" + (textBox1.Text) + "','" + (textBox2.Text) + "')";
ExcuteQuery(insertQuery);
fn();
}
And I have a question that is the form1 that I make it hide run in the background after the code
Application.OpenForms[0].Show();