C#:从任务管理器中隐藏多个表单 [英] C#: hiding multiple forms from task manager
问题描述
我正在编写一个应用程序,它可能会创建大量的表单来在桌面上显示小部件.尽管 ShowInTaskbar = false;,但该表单的每个实例都显示在任务管理器的应用程序列表中.实际上它们没有显示在任务栏中.
I'm writing an application which creates a potentially large number of forms to display widgets on the desktop. Every instance of that form shows up in the task manager's Applications list, despite ShowInTaskbar = false; and indeed they do not show in taskbar.
我想要的行为是任务管理器中只显示应用程序的主窗体,我该如何实现?
The behavior I want is that only the application's main form shows up in the task manager, how can I achieve this?
推荐答案
请注意,窗口也显示在 Alt+Tab 栏中.您需要通过覆盖 CreateParams 属性来更改窗口样式标志.这是一个完整的示例:
Note that the windows also show up in the Alt+Tab bar. You need to change the window style flags by overriding the CreateParams property. Here's a full example:
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
this.FormBorderStyle = FormBorderStyle.None;
this.ShowInTaskbar = false;
}
protected override CreateParams CreateParams {
get {
var cp = base.CreateParams;
cp.ExStyle |= 0x80; // Turn on WS_EX_TOOLWINDOW
return cp;
}
}
}
这篇关于C#:从任务管理器中隐藏多个表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!