最小化表单到系统托盘
我想隐藏我的表单,同时保持我的应用程序在后台运行。 我使用了notifyIcon,它始终保持可见。
我用过“this.Hide();”隐藏我的表单,但不幸的是我的应用程序关闭(也不例外)。
我也在使用线程,此表单位于第二个线程上。
请告诉我如何解决它。
I want to hide my form while keeping my application running in background.
I've used notifyIcon and it remains always visible.
I've used "this.Hide();" to hide my form but unfortunately my application gets close (no exception).
I am also using threading and this form is on second thread.
Please tell me how can I solve it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的水晶球说您已使用 ShowDialog() 来显示表单。是的,在模式对话框上调用 Hide() 将关闭它。因此,模式对话框通常会禁用应用程序中的所有窗口。如果您将其隐藏,则用户将无法返回到程序,因为没有任何窗口可供激活。该表单在另一个线程上运行,否则不会影响行为。
您需要调用 Application.Run(new SomeForm()) 来避免这种情况。现在它不是模态的,您可以轻松隐藏它。但实际上,确实避免在非 UI 线程上显示表单。没有理由,你的主线程已经很有能力了。
My crystal ball says that you've used ShowDialog() to show the form. Yes, calling Hide() on a modal dialog will close it. Necessarily so, a modal dialog normally disables all of the windows in the application. If you hide it then there's no way for the user to get back to the program, there are no windows left to activate. That this form runs on another thread otherwise doesn't factor into the behavior.
You'll need to call Application.Run(new SomeForm()) to avoid this. Now it isn't modal and you can hide it without trouble. But really, do avoid showing forms on non-UI threads. There's no reason for it, your main thread is already quite capable.
添加以下事件处理程序以调整表单大小并通知图标单击事件,
但这不会关闭您的应用程序
add the following event handlers for form resize and notify icon click event
but this is not close you application