I\'m trying to pass a value set in my parent form to a second form. I created a property with a get part in the parent form.
I don\'t want to do something like:
I'm not sure about how you are going to use the Form2
in the parent(let it be frmParent
). anyway you can follow any of the steps below:
Define the property in the child form as static so that you can access that by using Form2.frmProperty
.
Or define the property as public and then access through the class instance, so that you can access the variable through that instance as long as the instance existed. something like the following:
Form2 secondFormInstance = new Form2();
secondFormInstance.frmProperty = 10;
// at some later points
int childValue = secondFormInstance.frmProperty; // take value from that variable
secondFormInstance.frmProperty++; // update the value
Or you can use like what you specified in the question.