[英]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.