Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to pass values from one page to another in C# windows application.

And secondly,
how to close the the Active Form using code

Appreciate your feedback

Thanking You
Shaah
Posted
Comments
Toli Cuturicu 28-Sep-10 9:11am    
"... page ... windows application" ??

Example:

public partial class Result : Form
{
public string _data = "";
}


public partial class Form1 : Form
{
private void MakeResult()
{
Result result = new Result();
result._data = "Test";
result.Show();
}
}
 
Share this answer
 
v2
Comments
DaveyM69 28-Sep-10 17:40pm    
It's generally bad practice to expose a field directly. The field should be private and exposed by a public property. (I'm not the one who 3 voted you by the way!)
shakil0304003 1-Oct-10 1:28am    
I always use public property & make variable in private. I wanted to make my example sort, so i wrote that.
how to close the the Active Form using code


use Close method to close the form.
C#
this.Close();


Please vote and Accept Answer if it Helped.
 
Share this answer
 
v3
Comments
shanawazway 29-Sep-10 1:32am    
Closing of form is successful. Thanx.
but can u guide me how to pass value between two windows forms.
do you mean page or do you mean form?

You can pass values by invoking the constructor of the second form.

say you have Form A, Form B. You want to pass values from A to B. In the constructor of cllss Form B -

public Form B(var value)
{}

In Form A, invoke Form B with the value to pass.

FormB B = new FormB(value);
B.show();
Hope this helps.
 
Share this answer
 
Comments
[no name] 28-Sep-10 9:23am    
You can Pass Value From One Form To Another by Using Property.
Also
Dinesh Sharma
ankitaverma 17-Apr-12 7:46am    
please tell the method?
shanawazway 29-Sep-10 4:04am    
I tried using the property, but when it goes to other form, the value in the variable become NULL.

Is there any solution for this.

Thanks
It depends - properties/methods work if you want the parent form to request data from the child form.

If you want the child form to inform the parent that data is available then you should use events - see here[^].
 
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