简体   繁体   English

如何隐藏Windows窗体但保留任务栏条目?

[英]How do I hide a windows form but keep a Taskbar entry for it?

I'm writing a C# Windows Forms application. 我正在编写一个C#Windows Forms应用程序。 How do I hide the form while keeping it active in the Windows taskbar ? 如何在Windows任务栏中保持活动状态的同时隐藏该表单?

I've tried setting the Visible property to false and using the Hide() method, but they hide both the form and the taskbar entry. 我尝试将Visible属性设置为false并使用Hide()方法,但是它们同时隐藏了表单和任务栏条目。

I've also tried minimizing the application permanently by setting WindowState to FormWindowState.Minimized in the OnLoad and onResize events. 我还尝试通过在OnLoadonResize事件FormWindowState.Minimized WindowState设置为FormWindowState.Minimized来永久最小化应用程序。 This works pretty well, but when you left-click on the icon in the taskbar, you get a quick flash of the application before it resizes (which is kind of annoying). 这很好用,但是当您在任务栏上的图标上单击鼠标左键时,您会在应用程序调整大小之前快速浏览该应用程序(这很烦人)。

Sorry if this question has come up before, but every question that I've seen so far invovles hiding the taskbar completely, or removing the application as a taskbar item (to be replaced by a NotifyIcon ). 抱歉,如果以前已经出现过此问题,但是到目前为止,我所见的每个问题都涉及完全隐藏任务栏,或者将应用程序作为任务栏项删除(由NotifyIcon代替)。

How do I fix this problem? 我该如何解决这个问题?

Set

FormBorderStyle = None 

& in Load event: &在载入事件中:

private void Form1_Load(object sender, EventArgs e)
{
    this.Size = new System.Drawing.Size(0, 0);
}

As dequadin mentioned, the paradigm you're using probably justifies a notify icon. 如dequadin所述,您正在使用的范例可能证明了一个notify图标。 The taskbar is specifically designed for minimized windows (and on Win7, app launch). 任务栏是专门为最小化窗口而设计的(在Win7上是应用程序启动)。 All of the other recommendations (form opacity, moving the window offscreen, etc) fall down on Win7 with Aero Peek. 其他所有建议(窗体不透明,将窗口移到屏幕外等)均适用于带有Aero Peek的Win7。

If you have an app which is primarily a background task with occasional UI and the need for user interaction on demand, the correct technique is the System Notification Area (aka the Tray). 如果您的应用程序主要是带有偶尔UI的后台任务,并且需要按需进行用户交互,则正确的方法是系统通知区域(又称为托盘)。 In .NET WinForms, this would be the NotifyIcon control. 在.NET WinForms中,这将是NotifyIcon控件。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM