以不同的表单标签显示计算结果C#

发布于 2025-01-11 19:58:33 字数 194 浏览 4 评论 0原文

因此,我创建了一个简单的应用程序来计算学生的成绩。我所做的是创建两种表格,一种用于学生输入分数,另一种用于显示结果。

例如,在表格一中,学生输入两个分数,如 75 和 85,当他或她单击表格一中的计算按钮时,结果应显示在表格 2 标签中。

我应该怎么做才能将结果显示在表格二中。在形式二中不应该显示他们的分数或任何东西,它应该只显示结果。请帮忙。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

憧憬巴黎街头的黎明 2025-01-18 19:58:33

您可以创建一个类并创建两种形式都可以访问的静态变量。您将在计算表单中分配值,并且可以在其他表单中访问更新的值。

class MyClass
    {
        public static int finalGrade{ get; set; }
    }

然后您可以按如下方式使用该变量:

Form1
    {
        MyClass.finalGrade = value;
    }
Form2
    {
        label.text = MyClass.finalGrade.ToString();
    }

确保仅在值更改后才显示其他页面,或者您可以刷新页面以查看反映的更改

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文