引用Winform表格的问题

发布于 2025-02-13 22:01:27 字数 368 浏览 0 评论 0原文

我的bean有一个问题引用我在main中初始化的winform表单,引用的代码如下,

Form1 f1 = new Form1();
Application.Run(f1);
f1.changeText("Hello World");

表单本身在另一个文件中定义。 f1.changeText是一个简单的函数,它获取字符串输入并将文本块元素设置为字符串,我在单击按钮的结果中调用表单类中的函数,并且可以正常工作,但是当我在MAIN中调用它时,我会得到没有结果。作为旁注,我有一个控制台。主要功能在主要方面也无能为力,但我不知道这是否相关。在上下文中,我使用的是Visual Studio,如果不是很明显,我没有太多在类似的课程和框架编码的经验。感谢您的帮助!

I have bean having a issue referencing a winform form I initialize in main, the code for the referencing is as follows,

Form1 f1 = new Form1();
Application.Run(f1);
f1.changeText("Hello World");

the form itself is defined in another file. f1.changetext is a simple function which takes a string input and sets a text block element to the string, I call the function in the form class as the result of clicking a button and that works fine but when I call it in main I get no result. As a side note I have a console.writeline function in main as well that doesn't do anything but I don't know if that's related. For context I'm using Visual studio and if it wasn't obvious I don't have too much experience with coding with classes and frameworks like this. Thanks for any assistance!

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

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

发布评论

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

评论(1

烦人精 2025-02-20 22:01:28

我不熟悉application.run(f1);在“运行”之前,您也不应该更改文本吗?

它是:

Form1 f1 = new Form1();
f1.changeText("Hello World");
Application.Run(f1);

我敢肯定,显示 /初始化另一种表格的方法(我使用的一种)是否会

Form1 f1 = new Form1();
f1.changeText("Hello World");
f1.ShowDialog();

尝试调试来检查代码在运行时是否有效 /读取?

I'm not familiar with Application.Run(f1); also shouldnt you change the text prior to "Running it?"

It Being:

Form1 f1 = new Form1();
f1.changeText("Hello World");
Application.Run(f1);

A way I'm sure will work (the one I use) with showing / initializing another form would be

Form1 f1 = new Form1();
f1.changeText("Hello World");
f1.ShowDialog();

Have you tried Debug to check if the code works / was read when running?

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