Winforms - 为什么“Show()”系统托盘双击后,我的应用程序会最小化吗?
Winforms - 为什么系统托盘双击后“Show()”会在我的应用程序中最小化?
如何确保在通知图标双击事件中我隐藏的主窗体恢复正常可见,而不是最小化(也不是最大化)
Winforms - why does a "Show()" after a system tray double click end up in my app minimized?
How do I ensure Inthe notifyicon double click event that my hidden main form comes back visible as normal, not minimized (nor maximised for that matter too)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜您将应用程序放在最小化操作的托盘中。在这种情况下,Show 只是恢复可见性。
尝试在 Show() 之前添加
form.WindowState = Normal
。I would guess that you put your application in tray on minimize action. In that case, Show just restores visibility.
Try adding
form.WindowState = Normal
before Show().使用 NotifyIcon 隐藏表单通常是可取的,这样您的应用程序就会立即在托盘中启动。您可以通过重写 SetVisibleCore() 方法来防止它可见。您通常还希望防止它在用户单击 X 按钮时关闭,重写 OnFormClosing 方法以隐藏表单。您需要一个上下文菜单来允许用户真正退出您的应用程序。
将 NotifyIcon 和 ContextMenuStrip 添加到您的表单中。向 CMS 提供“显示”和“退出”菜单命令。使表单代码如下所示:
Hiding your form with the NotifyIcon is often desirable so your app starts in the tray right away. You can prevent it from getting visible by overriding the SetVisibleCore() method. You also typically want to prevent it from closing when the user clicks the X button, override the OnFormClosing method to hide the form. You'll want a context menu to allow the user to really quit your app.
Add a NotifyIcon and a ContextMenuStrip to your form. Give the CMS the Show and Exit menu commands. Make the form code look like this: