Monday 15 September 2014

c# - passing data from form2 into form1 and save it in a string variable -


I am passing data from Form2 to text2 in Form2 through another manufacturer.

After that, I want to set the textbox value to a global string variable in Form2

If I do so, I want the value of the global variable, but at that time Not far When I close the form 2 dialog ( this.Close () after the code), the main-constructor executes once and I am losing value for my global string variable. ...

I have a workaround where I save the textfile value in a text file and read it if I want it in it, but it is not the solution I am looking for.

I think you need a public property in Form 2. I have done this in the past (and it is easy and works well), but the code I am posting is not tested. This should start you.

Form 2 code: public string communication stuff {get; Set;} // Private set // if one-way communication communication stuff = myTextBox.Text;

and then after calling in form2 and it closes, you can say

FORM1 code: Form2 subform = new Form2; Subform.CommunicationStuff = "Default value based on program status"; Subform.ShowDialog (); String result = Subform. Communications Staff;

Edit: While searching for an example, I found this post:


No comments:

Post a Comment