下边讲述托盘的创建、点击窗体最小化桌面右下角会有托盘图标显示,双击图标,窗体恢复原样,点击关闭,窗体关闭,图标也不进行显示。
托盘的创建只需要把NotifyIcon控件拖入到窗体中即可,该控件没有图形可视化界面,图标样式在属性Icon属性中添加,必须是.icon格式。
代码如下
/// <summary>
/// 关闭
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ActInfoForm_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
ActInfo.Visible = true;
this.Hide();
this.ShowInTaskbar = false;
ActInfo.Dispose();//释放资源
}
/// <summary>
/// 双击托盘继续显示
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void notifyIcon_DoubleClick(object sender,