So I've create a simple app that calculates students grade. What I have done is created two form, one is for where students enter their marks and form two for display the result.
For example, in form one students enter two marks like 75 and 85 and when he or she click the calculate button in form one the result should show in the form 2 label.
What should I do for display the result in form two. In form two should not show their marks or anything, it should only show result. Please help.
CodePudding user response:
You can create a class and make static variables that will be accessible to both forms. You will assign values in the calculation form and the updated values can be accessed in other forms.
class MyClass
{
public static int finalGrade{ get; set; }
}
Then you can use the variable as follows:
Form1
{
MyClass.finalGrade = value;
}
Form2
{
label.text = MyClass.finalGrade.ToString();
}
Make sure to show the other page only after the values have been changed or you could refresh the page to see the reflected changes