基础知识之最大化,最小化,系统托盘图标,右键菜单,提示气球
琢磨了一下C/S软件,打算做一个,先记录一下基础的东西
1.最小化
WindowState = FormWindowState.Minimized;
//最小化时隐藏窗体
this.Visible=false;
2.最大化
WindowState == FormWindowState.Maximized;
3.还原为正常
WindowState == FormWindowState.Normal;
4.系统托盘图标
加notifyicon控件notifyicon1,为控件notifyicon1的属性icon添加一个icon图标。
/// <summary>
/// 显示出来
/// </summary>
private void BigShow()
{
this.Visible = true;
this.WindowState = FormWindowState.Normal;
this.notifyIcon1.Visible = false;
}
/// <summary>
/// 最小化
/// </summary>
private void MinHide()
{
if (this.WindowState == FormWindowState.Minimized)
{
this.notifyIcon1.ShowBalloonTip(3, "提示", "您已经最小化,可以点击这里出来", ToolTipIcon.Info);
this.Hide();
this.notifyIcon1.Visible = true;
}
}
5.可以给notifyicon添加右键菜单:
主窗体中拖入一个contextmenu控件contextmenu1,点中控件,在上下文菜单中添加菜单,notifyicon1的contextmenu行为中选中contextmenu1作为上下文菜单。
6.点出来,右键菜单
private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)//左键最大化
{
this.BigShow();
}
else if(e.Button==MouseButtons.Right)//右键弹出菜单
{
}
}
7.关闭程序
Application.Exit();