C# 是否可以在 TaskManager 应用程序选项卡中隐藏 winform?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9232291/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 06:28:04  来源:igfitidea点击:

Is it possible to hide winform in TaskManager application tab?

c#.netwinformstaskmanager

提问by adi sba

I'm writing a transparent WinForms app and I want to hide the app from showing in Task Manager's applications tab. I'm OK with the fact that it will show in Processes (in fact it should). If I set:

我正在编写一个透明的 WinForms 应用程序,我想隐藏该应用程序,使其不显示在任务管理器的应用程序选项卡中。我对它会显示在进程中的事实感到满意(实际上它应该)。如果我设置:

this.ShowInTaskbar = false;

it only hides from taskbar.

它只从任务栏隐藏。

Full code i have i have a timer made from labels

完整代码我有一个由标签制成的计时器

        public Form1()
    {
        InitializeComponent();
        this.BackColor = Color.LimeGreen;
        this.TransparencyKey = Color.LimeGreen;
        Timer time = new Timer();
        time.Interval = 1000;
        time.Tick += new EventHandler(time_Tick);
        time.Start();
        this.ShowInTaskbar = false;


    }

    void time_Tick(object sender, EventArgs e)
    {
        label1_hour.Text = DateTime.Now.Hour.ToString() ;
        label_minute.Text = DateTime.Now.Minute.ToString();
        label_second.Text = DateTime.Now.Second.ToString();
    }

采纳答案by MethodMan

Try something like this

尝试这样的事情

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;
        }
    }
}

回答by Joe Gayetty

Simply setting the form property FormBorderStyle to FixedToolWindow worked for me. On Win 10 it removes it from "Apps" in Task Manager and puts it in "Background processes"...which the OP specified (and was what I wanted also.)

只需将表单属性 FormBorderStyle 设置为 FixedToolWindow 对我有用。在 Win 10 上,它将它从任务管理器中的“应用程序”中删除,并将其放在“后台进程”中……这是 OP 指定的(也是我想要的。)

In addition, it removes the form from showing in "Windows Key + Tab" listing of windows...which is what I wanted as well.

此外,它还从窗口的“Windows 键 + 选项卡”列表中删除了表单……这也是我想要的。