最小化到系统托盘 [英] Minimize to system tray

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

问题描述

当您单击退出按钮时,我希望应用程序最小化到系统托盘,而不是任务栏,有点像您的防病毒软件。

When you click on the exit button, i want the application to minimize to the system tray, not to the task bar, kinda like the way your antivirus does.

推荐答案

将您的申请表发送到系统托盘中将NotifyIcon控件拖放到表单中。



To send your application form into the system tray Drag and drop a NotifyIcon control to your form.

private void mainForm_FormClosing(object sender, FormClosingEventArgs e)
{
   e.Cancel = true;
   this.WindowState = FormWindowState.Minimized;
   this.ShowInTaskbar = false;
   notifyIcon1.ShowBalloonTip(2, "Marketplace Retriever", "Marketplace Retriever is still running. If you want to use the tool please double click the icon to resize.", ToolTipIcon.Info);
   notifyIcon1.Visible = true;            
}





Goodluck



Goodluck


private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
    if (e.CloseReason == CloseReason.UserClosing)
    {
        e.Cancel = true;
        this.WindowState = FormWindowState.Minimized;
        this.ShowInTaskbar = false;
        this.Hide();
        notifyIcon1.Visible = true;
    }
}

private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
    Application.Exit();
}





与其他海报解决方案相同,但有一些修改。

First你需要this.Hide()(或this.visible = false;)来隐藏Alt + Tab菜单中的表单。

其次要确保你调用Application.Exit()而不是this.Close ()来自你的上下文菜单退出菜单项。

三,如果用户通过点击红色X或按Alt + F4关闭所有其他接近原因即窗口,if语句只会这样做正在关闭,通过任务管理器等关闭,应用程序将正常退出。



Same as the other posters solution but with a couple of modifications.
First you need this.Hide() (or this.visible = false;) to hide the form from the Alt + Tab menu.
Second make sure you call Application.Exit() instead of this.Close() from your context menus exit menu item.
Third the if statement says to only do this if the user closed the app by click the red X or pressing Alt + F4 for all other close reasons i.e. windows is shutting down, closed through the task manager, etc. the application will exit normally.


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

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