最小化到托盘使表格不可见 [英] Minimize to tray make form unvisible

查看:77
本文介绍了最小化到托盘使表格不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 NotifyIcon 使表单最小化,以便在后台运行。

I am using NotifyIcon to make my form minimize to tray to work at background.

但是下面的代码根本不显示应用程序图标。形式变得完全不可见。我必须从任务管理器中删除它。

However below code doesn't show app icon at all. Form goes totally invisible. I have to kill that from task manager.

private void Button1_Click(object sender, EventArgs e)
{
    this.WindowState = FormWindowState.Minimized;
    if (FormWindowState.Minimized == this.WindowState)
    {   
        Hide();
        this.ShowInTaskbar = false;
        notifyIcon1.Visible = true; 
    }
}

可能是什么原因?我想看到我的应用程序图标重新打开表单。

What could be the reason? I want to see my app-icon to re-open the form.

推荐答案

您需要分配一个图标 NotifyIcon 显示在系统任务栏中。另外,您还需要将 Visible 设置为 true

You need to assign an Icon to NotifyIcon to show it in system tray. Also you need to set Visible to true.

您可以在设计时使用属性网格设置属性,也可以通过代码设置属性。例如,您可以使用以下代码:

You can set properties using property grid at design time or you can set them by code. For example, you can use such code:

this.notifyIcon1.Icon = this.Icon;
this.notifyIcon1.Visible = true;

如果您未设置图标或可见对象不为真,则不会显示图标。

If you don't set the Icon or if the visible is not true, it will not show the icon.

这篇关于最小化到托盘使表格不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆