找不到类型或命名空间窗口
我很困惑为什么下面的代码不会出现窗口。我错过了进口吗?
using System.Text;
using System.Xml;
using System.Windows;
using System;
using System.Windows.Forms;
using System.IO;
using System.Threading;
public class Program {
public Window mainWindow;
static void main() {
// Create the application's main window
mainWindow = new Window();
mainWindow.Title = "Enter SN";
mainWindow.Show();
}
}
I am confused as to why a Window will not appear with the below code. Am I missing an import?
using System.Text;
using System.Xml;
using System.Windows;
using System;
using System.Windows.Forms;
using System.IO;
using System.Threading;
public class Program {
public Window mainWindow;
static void main() {
// Create the application's main window
mainWindow = new Window();
mainWindow.Title = "Enter SN";
mainWindow.Show();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想通过 Application.Run 运行窗口() 调用。您当前的代码不会在标准 Windows 消息循环上触发它,这是必需的。
删除 Show() 调用并将其替换为:
更简单的是,如果您在 WinForms 设计器上按照自己的意愿设置标题,则 main 可以是单行:
另外,您还有许多不必要的 using 语句。这些陈述并不是真正的问题,只是不必要且令人困惑。
You want to run your Window via an Application.Run() call. Your current code will not fire it off on a standard windows message loop, which is required.
Remove your Show() call and replace it with:
To be even simpler, if you set your title as your wish on your WinForms designer, your main can be a single line:
Also, you have many unnecessary using statements. These statements aren't a real problem, just unnecessary and confusing.