简体   繁体   English

Visual Studio 2022 当点击外部应用程序最小化时 go 没有恢复正常

[英]Visual Studio 2022 When clicking outside application to minimize It doesn't go back to normal

I made this simple little application which goes in the notification area (the little arrow on the taskbar which holds a few applications that run in the background).我制作了这个简单的小应用程序,它位于通知区域(任务栏上的小箭头,其中包含一些在后台运行的应用程序)。

I have a button made where I can minimize it using:我制作了一个按钮,可以使用以下方法将其最小化:

this.WindowState = FormWindowState.Minimized;

and I can put the WindowState back to normal mode with:我可以通过以下方式将 WindowState 恢复到正常模式:

this.WindowState = FormWindowState.Normal;

This all works fine however when I try to click outside the application to minimize it, instead of pressing the button for it, it doesn't wanna go back to the normal state, even if I use the statement mentioned before.这一切都很好,但是当我尝试在应用程序外部单击以最小化它时,而不是按下它的按钮,它不想 go 回到正常的 state,即使我使用前面提到的语句。

Is there any setting I can use to toggle this behaviour, or do I need to change something inside the script and if so, what?是否有任何设置可以用来切换此行为,或者我是否需要更改脚本内部的某些内容,如果需要,该怎么办?

I've tried searching through the different settings on both the NotifyIcon and the ContextMenuStrip but couldn't find anything relevant but I might have also just missed it.我尝试搜索 NotifyIcon 和 ContextMenuStrip 上的不同设置,但找不到任何相关内容,但我可能也只是错过了它。

I've also tried to search through stackoverflow, but I'm not really sure what to search for, since nothing really popped up when trying to search for almost the same thing as the title on this thread.我也尝试通过 stackoverflow 进行搜索,但我不太确定要搜索什么,因为在尝试搜索与该线程上的标题几乎相同的内容时,并没有真正弹出任何内容。

Current Code:当前代码:

        private void button1_Click(object sender, EventArgs e)
        {
            File.WriteAllText("count.txt", count.ToString()); // Ignore this
            this.WindowState = FormWindowState.Minimized;
        }

        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            this.WindowState = FormWindowState.Normal;
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void showToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Normal;
        }

Figured out that the issue was not about it minimizing the form, however it was prioritizing the window I was clicking on.我发现问题在于它最小化了表单,而是它优先考虑了我点击的 window。 To fix this and change it to the top I used要解决此问题并将其更改为我使用的顶部

this.TopMost = true

Which worked perfectly.效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 片段不适用于 Visual Studio 2022 - Snippets doesn't work on Visual Studio 2022 “使用”行中的 Visual Studio for Mac 2022“转到定义”不起作用 - Visual Studio for Mac 2022 "Go to Definition" in "using" lines doesn't work visual studio 2022 .NET 6 当 DbContext 在一个单独的项目中时脚手架不起作用 - visual studio 2022 .NET 6 Scaffolding doesn't work when DbContext is in a separate project 程序在Visual Studio外部无法正常工作 - Program doesn't work outside Visual Studio 调试多个项目时,Visual Studio 2022 不会“启动”应用程序 - Visual Studio 2022 does not "start" application when debugging multiple projects 在 Visual C# 中最小化不起作用时隐藏表单 - Hide form when minimize doesn't work in Visual C# 单击工具中的加载项后,如何返回Visual Studio? - how can i go back to the visual studio after clicking add-in from tools WinForms应用程序无法在Visual Studio外部运行 - WinForms App Doesn't Run Outside Visual Studio 无法最小化 Visual Studio 中的注释代码 - Can't minimize commented code in Visual Studio xaml window 样式不适用于设计器模式 (visual studio 2022) - xaml window style doesn't apply at designer mode (visual studio 2022)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM