private void button6_Click(object sender,EventArgs e) { this.WindowState = FormWindowState.Minimized; }
然而,我没有去任务栏,而是希望它在托盘中出现(没有弹出窗口),只是应用程序图标,当有人点击它时,它需要设置这个
this.WindowState = FormWindowState.Normal;
这可能吗,怎么样?
系统托盘也是指右下角的那个,紧挨着时间
我仍然无法让这个工作,如果我按你们所说的那样在通知栏中没有出现(顺便说一下:这是最小化的完整代码)
private void button6_Click(object sender,EventArgs e) { this.WindowState = FormWindowState.Minimized; } private void Form_Resize(object sender,EventArgs e) { if (WindowState == FormWindowState.Minimized) { this.Hide(); } } private void notifyIcon_Click(object sender,EventArgs e) { this.Show(); this.WindowState = FormWindowState.Normal; }
为什么这不起作用?
解决方法
Handle the form’s Resize event. In this handler,you override the@H_403_2@ basic functionality of the Resize event to make the form minimize to@H_403_2@ the system tray and not to the taskbar. This can be done by doing the@H_403_2@ following in your form’s Resize event handler:
>检查表单的WindowState属性是否设置为FormWindowState.Minimized.如果是,请隐藏表单,启用NotifyIcon对象,并显示显示某些信息的气球提示.@H_403_2@>一旦WindowState成为FormWindowState.Normal,通过将其Visible属性设置为false来禁用NotifyIcon对象.@H_403_2@>现在,当您双击任务栏中的NotifyIcon对象时,您希望窗口重新出现.为此,处理NotifyIcon的MouseDoubleClick事件.在这里,您使用Show()方法显示表单.
在表单resize事件中,执行检查并隐藏表单
private void Form_Resize(object sender,EventArgs e) { if (WindowState == FormWindowState.Minimized) { this.Hide(); } }
然后单击任务栏图标时,只需将其恢复.
private void notifyIcon_Click(object sender,EventArgs e) { this.Show(); this.WindowState = FormWindowState.Normal; }
参考:@H_403_2@How do I minimize a WinForms application to the notification area?@H_403_2@minimize app to system tray