C#最小化到关闭时的系统托盘 [英] C# Minimize to system tray on close
本文介绍了C#最小化到关闭时的系统托盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的C#应用程序中,当表单关闭时,我试图最小化对系统托盘的应用程序.这是我尝试过的代码.
Hi In my c# application I am trying to minimize application to systems tray, when the form is closed. Here is the code I have tried.
public void MinimizeToTray()
{
try
{
notifyIcon1.BalloonTipTitle = "Sample text";
notifyIcon1.BalloonTipText = "Form is minimized";
if (FormWindowState.Minimized == this.WindowState)
{
notifyIcon1.Visible = true;
notifyIcon1.ShowBalloonTip(500);
this.Hide();
}
else if (FormWindowState.Normal == this.WindowState)
{
notifyIcon1.Visible = false;
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
,并且我正在调用该方法来形成关闭事件.但是问题在于它没有最小化托盘.它只是关闭窗体.
and I am calling the method to form closing event. But the problem is its not minimizing to tray. Its just closing the form.
推荐答案
在表单关闭"事件中编写一个事件.
Write a event in Form Closing event.
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
Hide();
}
然后使用自定义"菜单条编写要显示的通知图标.
And write using Custom menu strip for notification icon for to show.
这篇关于C#最小化到关闭时的系统托盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文