如何创建没有表单的notifyIcon
本文关键字:表单 notifyIcon 何创建 创建 | 更新日期: 2023-09-27 17:50:11
我在容器中添加了notifyIcon并设置了Visible = true选项,但是没有图标出现
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
this.SuspendLayout();
//
// notifyIcon1
//
this.notifyIcon1.Text = "Manager";
this.notifyIcon1.Visible = true;
//
// Form1
//
this.ClientSize = new System.Drawing.Size(0, 0);
this.ShowInTaskbar = false;
this.Visible = false;
}
我相信你需要添加更多的事件,这工作,希望这有助于
public Form2()
{
InitializeComponent();
notifyIcon1.Icon = SystemIcons.Asterisk;
notifyIcon1.DoubleClick += new EventHandler(notifyIcon1_DoubleClick);// to bring it back
this.Resize += new EventHandler(Form2_Resize);// to move it to tray
}
void notifyIcon1_DoubleClick(object sender, EventArgs e)
{
Show();
this.BringToFront();
this.WindowState = FormWindowState.Normal;
}
void Form2_Resize(object sender, EventArgs e)
{
if (this.WindowState ==FormWindowState.Minimized)
Hide();
}
notify图标在窗体最小化时显示。试试这个
this.WindowState = FormWindowState.Minimized;