C#如何实现最小化后只在状态栏显示

NickyNiky 2010-08-16 12:44:07
当我把程序最小化后,我想只在状态栏显示,怎么用代码实现啊?
...全文
386 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
1、建个WinForm项目,其它操作略过。2、拉个NotifyIcon控件,将属性Visable设置成False,在Text属性上随便填些文件。3、实现Form的SizeChanged事件,代码如下:

if(this.WindowState == FormWindowState.Minimized) //判断是否最小化
{
this.ShowInTaskbar =false; //不显示在系统任务栏
notifyIcon.Visible =true; //托盘图标可见
}

4、实现NotifyIcon控件的DoubleClick事件,代码如下:

if(this.WindowState == FormWindowState.Minimized)
{
this.ShowInTaskbar =true; //显示在系统任务栏
this.WindowState = FormWindowState.Normal; //还原窗体
notifyIcon.Visible =false; //托盘图标隐藏
}
PS:这种问题直接百度要快得多,不用在这里傻等着
68435970 2010-08-17
  • 打赏
  • 举报
回复

private void InitializeComponent_tray()
{
this.SuspendLayout();
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(320, 56);
this.ControlBox = false;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.WindowState = System.Windows.Forms.FormWindowState.Minimized;

this.Name = "tray";
this.ShowInTaskbar = false;
this.Text = "用Visual C#做托盘程序!";
this.ResumeLayout(false);
}
private Icon printIcon ;//打印图标
private NotifyIcon TrayIcon;
private ContextMenu notifyiconMnu;
private MenuItem[] mnuItms;
/// <summary>
/// 设置证书制作和打印为托盘程序
/// </summary>
private void Initializenotifyicon()
{
CurrentMethod method = new CurrentMethod();
string first = method.ConfigGetValue("StartOrEnd");
//设定托盘程序的各个属性
TrayIcon = new NotifyIcon();
string str_path = string.Empty;
str_path = System.Windows.Forms.Application.StartupPath + "\\" + "edit.ico";
printIcon = new Icon(str_path);//打印图标
TrayIcon.Icon = printIcon;
TrayIcon.Text = "质检报告制作打印服务";
//定义一个MenuItem数组,并把此数组同时赋值给ContextMenu对象
mnuItms = new MenuItem[5];
if (first == "0")//开机自启动
{
mnuItms[0] = new MenuItem();
mnuItms[0].Text = "开机不启动";
mnuItms[0].Click += new System.EventHandler(this.NoOpenStart);
}
else
{
mnuItms[0] = new MenuItem();
mnuItms[0].Text = "开机自启动";
mnuItms[0].Click += new System.EventHandler(this.OpenStart);

}
mnuItms[0].DefaultItem = true;
mnuItms[1] = new MenuItem("-");
mnuItms[2] = new MenuItem();
mnuItms[2].Text = "打印机配置";
mnuItms[2].Click += new System.EventHandler(this.showmessage);
mnuItms[2].DefaultItem = true;

mnuItms[3] = new MenuItem("-");

//mnuItms[4] = new MenuItem();
//mnuItms[4].Text = "条码配置";
//mnuItms[4].Click += new System.EventHandler(this.Print_BarCode_Config);
//mnuItms[4].DefaultItem = true;

//mnuItms[5] = new MenuItem("-");

mnuItms[4] = new MenuItem();
mnuItms[4].Text = "退出系统";
mnuItms[4].Click += new System.EventHandler(this.ExitSelect);
mnuItms[4].DefaultItem = true;

TrayIcon.Visible = true;
TrayIcon.Click += new System.EventHandler(this.click);

notifyiconMnu = new ContextMenu(mnuItms);
TrayIcon.ContextMenu = notifyiconMnu;
//为托盘程序加入设定好的ContextMenu对象
}
whltian 2010-08-16
  • 打赏
  • 举报
回复
网上有代码

1,978

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 其他语言讨论
社区管理员
  • 其他语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧