Forms
-
I have two forms. With a button on each. The click event of the button on the first form is as follows
Form2 form2;
private void button1_Click(object sender, EventArgs e)
{
if (form2 == null)
{
form2 = new Form2();
form2.Show();
}
}I want the button on the second form to bring back the first form on top with the BringToFront() method. How do I access the first form as there is no variable for it.
-
I have two forms. With a button on each. The click event of the button on the first form is as follows
Form2 form2;
private void button1_Click(object sender, EventArgs e)
{
if (form2 == null)
{
form2 = new Form2();
form2.Show();
}
}I want the button on the second form to bring back the first form on top with the BringToFront() method. How do I access the first form as there is no variable for it.
-
I have two forms. With a button on each. The click event of the button on the first form is as follows
Form2 form2;
private void button1_Click(object sender, EventArgs e)
{
if (form2 == null)
{
form2 = new Form2();
form2.Show();
}
}I want the button on the second form to bring back the first form on top with the BringToFront() method. How do I access the first form as there is no variable for it.
If you modify the form2 constructor to take a Form instance that would be form1 and keep it in your form2 instance, for further use.
-
thanx this solves the particular problem. but I would like to know if there is anyway to get a hold of form1 from form2.
-
If you modify the form2 constructor to take a Form instance that would be form1 and keep it in your form2 instance, for further use.
How would I pass an instance of form1 as there is no variable for it. It is being initialized in the Program.cs
Application.Run(new form1())
method.
-
How would I pass an instance of form1 as there is no variable for it. It is being initialized in the Program.cs
Application.Run(new form1())
method.
Look up this
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego. -
How would I pass an instance of form1 as there is no variable for it. It is being initialized in the Program.cs
Application.Run(new form1())
method.
public Form2(Form parentForm) { } Form2 form2; private void button1_Click(object sender, EventArgs e) { if (form2 == null) { form2 = new Form2(this); form2.Show(); } }
-
public Form2(Form parentForm) { } Form2 form2; private void button1_Click(object sender, EventArgs e) { if (form2 == null) { form2 = new Form2(this); form2.Show(); } }
Thanx that helped
-
Thanx that helped
Anytime :)
-
I have two forms. With a button on each. The click event of the button on the first form is as follows
Form2 form2;
private void button1_Click(object sender, EventArgs e)
{
if (form2 == null)
{
form2 = new Form2();
form2.Show();
}
}I want the button on the second form to bring back the first form on top with the BringToFront() method. How do I access the first form as there is no variable for it.
humayunlalzad wrote:
Form2 form2; private void button1_Click(object sender, EventArgs e) { if (form2 == null) { form2 = new Form2(); form2.Show(); } }
this code creates a new instance if form2 is not already opened, But what to do if form2 is opened and then closed by user(by X button of form2). i tried in else part of your block like this else { form2.BringToFront(); form2.Activate(); } but its not working. I think when user close the form2 it got disposed, but form2 instance not set to null. How to solve this? thanks and regards.
-
I have two forms. With a button on each. The click event of the button on the first form is as follows
Form2 form2;
private void button1_Click(object sender, EventArgs e)
{
if (form2 == null)
{
form2 = new Form2();
form2.Show();
}
}I want the button on the second form to bring back the first form on top with the BringToFront() method. How do I access the first form as there is no variable for it.
listen, i dont know what you are trying to achieve but use the mdi forms parent/child method instead in the future. i dont see the purpose of using many forms (or use usercontrols like pages). :)
nelsonpaixao@yahoo.com.br trying to help & get help
-
humayunlalzad wrote:
Form2 form2; private void button1_Click(object sender, EventArgs e) { if (form2 == null) { form2 = new Form2(); form2.Show(); } }
this code creates a new instance if form2 is not already opened, But what to do if form2 is opened and then closed by user(by X button of form2). i tried in else part of your block like this else { form2.BringToFront(); form2.Activate(); } but its not working. I think when user close the form2 it got disposed, but form2 instance not set to null. How to solve this? thanks and regards.
Yes you are rt. Thanx for pointing out the prob. I tried to set form2 to null in the form2 closing event, but I dont why it's not working. but this works
private void button1_Click(object sender, EventArgs e)
{
if (form2 == null)
{
form2 = new Form2(this);
form2.Show();
}
else if (form2.IsDisposed)
{
form2 = new Form2(this);
form2.Show();
}
else
{
form2.Focus();
}
}The only problem is that if I want to work on form2 and close form1, form2 also closes since form2.Show() had been called. Is there a way to keep form2 running even after form1 has been closed Guys Help
-
listen, i dont know what you are trying to achieve but use the mdi forms parent/child method instead in the future. i dont see the purpose of using many forms (or use usercontrols like pages). :)
nelsonpaixao@yahoo.com.br trying to help & get help
Its just about understanding the mechanism. But thanx anyways.
-
Its just about understanding the mechanism. But thanx anyways.
listen, if you are studying that method ok, go ahead, but like i said if you are trying to build some kind of application and you are thinking on using that method...drop it :laugh: i create applications using a single form!!! :) then a fill the form with lots of usercontrols that are pages. Or you can use mdi parent/child form method.
nelsonpaixao@yahoo.com.br trying to help & get help