Click here to Skip to main content
16,008,010 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hello i have 2 forms
form1 has button and drop downlist.
form two has two links and a ok button

when i click on button(form1) it shows form 2 if i select any of one link( from form2 in active), it shoud close form2 and should run event based on form1 focus gained event.

Please help how to write the focus gained event..........
Thanks in advance..
Posted

I don't think you explained that too well.

There are two ways to show a form from your button click event:
C#
Form2 f = new Form2();
f.Show();
And
C#
Form2 f = new Form2();
f.ShowDialog();
Depending on which one you choose, how your code should work will change.
The first version opens your new form, but allows it and Form1 to continue side-by side. You can enter data in both, or press the button in Form1 again to get another copy of Form2 running at teh same time.
The second version opens your new form, but does not return control to Form1 until the user closes Form2. Form1 remains inactive and can do no more actions until this happens.

If you use the former, then you need to explain in more detail what you are trying to achieve.

If you use the later, then you need to set up a public property in Form2 to return the user's choice to Form1
 
Share this answer
 
You can do something like this.

On Form2, you can have a public variable. You set that variable when the link is clicked.
C#
bool LinkClicked = false;
private void LinkLabel1_LinkClicked(System.Object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
	LinkClicked = true;
}


On Form1, use ShowDialog to show the Form2. When the form is closed then only execution resumes beyond ShowDialog. There you can check LinkClicked using form instance.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900