如何以另一种形式使用组合框中的数据c#

发布于 2025-01-16 07:15:47 字数 704 浏览 3 评论 0原文

我正在用 C#(Visual Studio、Windows 窗体)编写一个程序,其中涉及用户从组合框中选择一个名称,然后单击一个按钮,将他们带到另一个窗体上的测验。我希望在测验结束时创建一个文本文件,显示所选名称和测验结果,后跟“~”符号。

老实说,我不知道从哪里开始。我正在使用流阅读器。

这是我用于组合框和将您发送到下一个表单的按钮的代码


 private void quizSelectPupilCB_SelectedIndexChanged(object sender, EventArgs e)
        {
            selectedClass = quizSelectPupilCB.SelectedItem.ToString();
        }

        private void quizStartBTN_Click(object sender, EventArgs e)
        {
            Quiz2 formQuiz2 = new Quiz2();
            formQuiz2.Show();
            this.Hide();
        }

如何在另一个表单上使用此数据?

我什至不知道从哪里开始。我尝试查找诸如“如何从一种表单访问数据并将其放入另一个 c# 中”之类的内容以及类似的内容,但我发现的所有内容要么不是我想要的,要么是以一种非常令人困惑的方式措辞的。

I'm writing a program in c# (visual studio, windows forms) which involves the user selecting a name from a combo box, and then clicking a button which brings them to a quiz on another form. I want a text file to be created at the end of the quiz showing the name selected and the quiz results, followed by a "~" symbol.

I honestly don't know where to start. I'm using stream reader.

This is the code I used for the combo box and the button that sends you to the next form


 private void quizSelectPupilCB_SelectedIndexChanged(object sender, EventArgs e)
        {
            selectedClass = quizSelectPupilCB.SelectedItem.ToString();
        }

        private void quizStartBTN_Click(object sender, EventArgs e)
        {
            Quiz2 formQuiz2 = new Quiz2();
            formQuiz2.Show();
            this.Hide();
        }

How do I use this data on another form?

I don't even know where to start. I tried looking up things like "how to access data from one form and put it in another c#" and similar things but everything I found was either not what I was looking for, or worded in a really confusing way.

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

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

发布评论

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

评论(1

巴黎夜雨 2025-01-23 07:15:47

作为一种变体,您可以将 selectedItem 保存到 String/StringCollection,然后保存到应用程序设置(Settings.Default)。并在另一种形式上取回该值。

As a variant you can save selectedItem to String/StringCollection, then to app settings(Settings.Default). And on another form get this value back.

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