C# 运行 Windows 窗体应用程序不以窗体开头
我希望我的程序以气球图标启动,一旦单击它就会出现一个窗口,但是当我尝试运行我制作的显示消息的类时,我无法运行它,因为它不是表单。基本上我可以弹出一个气球警报,但是一旦单击它就不会打开表单,因为程序似乎已经终止(Program.cs 中的 Main() 已经完成)
我尝试了这样的东西:
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
new TrayIcon();
}
但它只显示警报并且不起作用。
如果我将 TrayIcon 类设置为部分表单并使用 Application.Run() 它可以工作,但也会弹出一个空的、丑陋的表单。
那么如何才能让气球先弹出而不让程序结束呢?
I want my program to start with a balloon icon and once it is clicked for a window to come up but when I try to run a class I made that shows the message, I cant run it because it's not a form. Basically I could get a balloon alert to pop up but Once clicked it would not open the form because it seems like the program already terminated (Main() in Program.cs already finished)
I tried stuff like this:
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
new TrayIcon();
}
but it just shows the alert and doesn't work.
If I make my TrayIcon Class a partial Form and Used Application.Run() It works but an empty, ugly form pops up too.
So how can I just make the balloon pop up at first without the program ending?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需使用不带 Form 参数的 Application.Run 重载:
这将在当前线程上启动 Windows 消息循环,该循环将处理 UI 消息,包括通知图标变得可见和响应所需的消息。
Just use the Application.Run overload that does not take a Form parameter:
This will start a Windows message loop on the current thread, which will process UI messages, including those necessary for your notifyicon to become visible and responsive.