C#: hiding multiple forms from task manager

2020-04-21 02:45发布

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?

标签: c# winforms
2条回答
够拽才男人
2楼-- · 2020-04-21 03:28

You could try setting FormBorderStyle to one of the tool window options - FixedToolWindow or SizaableToolWindow. I think that tool windows don't show up in task manager's list of applications, but I'm not positive on that.

查看更多
Evening l夕情丶
3楼-- · 2020-04-21 03:49

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;
        }
    }
}
查看更多
登录 后发表回答