使用NotifyIcon 组件,然后把form的ShowInTaskbar 属性设为false;
解决方案 »
- c# ADSL断网重启总不成功
- excel列名问题
- 做简单图形报表开发用什么技术比较合适?
- System.InvalidOperationException: 已有打开的与此命令相关联的 DataReader,必须首先将它关闭。
- .net 高手请进
- 服务器信息传递
- 不是可识别的表提示选项。如果它要作为表值函数的参数,请确保您的数据库兼容模式设置为90
- z顺序不能控制吗
- 求C#的 lockbits 雕刻 浮雕 算法
- C# XMl转为DataTable 总是自动多出一列 table_id 哪位遇到过?
- 关于执行多次Sql查询的问题
- 我下载了一个在WEBFROM 上用的TreeView控件的问题?在线等!
发现最小化后,任务栏上面还有显示,
ShowInTaskbar=false后,它在什么时刻都不走任务栏显示了有没有什么好办法使得当最小化时候,不在任务栏里面显示,但正常或者最大化的时候都会在任务栏里面显示出来
好像要编写最小化的代码,最小化的事件是什么呢?
{
if (this.WindowState == FormWindowState.Minimized)
this.ShowInTaskbar = false;
else
this.ShowInTaskbar = true;
}
/// 在窗体最大最小时接收事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_Resize(object sender, System.EventArgs e)
{
//如果窗体最小化,哪么就隐藏窗体
if (this.WindowState == FormWindowState.Minimized)
{
this.Visible = false;
}
} /// <summary>
/// 上下文菜单
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem1_Click(object sender, System.EventArgs e)
{
//显示窗体
this.Visible=true;
//将窗体显示为默认状态
this.WindowState=FormWindowState.Normal;
} private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
//是否响应窗体关闭事件
e.Cancel=true;
//隐藏窗体
this.Visible=false;
}
using System.Drawing ;
using System.Collections ;
using System.ComponentModel ;
using System.Windows.Forms ;
using System.Data ;//导入在程序中使用到的名称空间
namespace WindowsApplication1
{
public class Tray : Form
{
private System.ComponentModel.Container components = null ;
private Icon mNetTrayIcon = new Icon ( "NET10B.ico" ) ;
private NotifyIcon TrayIcon ;
private ContextMenu notifyiconMnu ; public Tray()
{
//初始化窗体中使用到的组件
InitializeComponent ( ) ;
//初始化托盘程序的各个要素
Initializenotifyicon ( ) ;
} private void Initializenotifyicon ( )
{
//设定托盘程序的各个属性
TrayIcon = new NotifyIcon ( ) ;
TrayIcon.Icon = mNetTrayIcon ;
TrayIcon.Text = "辽河应用服务器" ;
TrayIcon.Visible = true ;
TrayIcon.DoubleClick += new System.EventHandler ( this.Tray_DoubleClick ) ; //定义一个MenuItem数组,并把此数组同时赋值给ContextMenu对象
MenuItem [ ] mnuItms = new MenuItem [ 3 ] ;
mnuItms [ 0 ] = new MenuItem ( ) ;
mnuItms [ 0 ] .Text = "辽河应用服务器!" ;
mnuItms [ 0 ] .Click += new System.EventHandler ( this.showmessage ) ; mnuItms [ 1 ] = new MenuItem ( "-" ) ; mnuItms [ 2 ] = new MenuItem ( ) ;
mnuItms [ 2 ] .Text = "退出系统" ;
mnuItms [ 2 ] .Click += new System.EventHandler ( this.ExitSelect ) ;
mnuItms [ 2 ] .DefaultItem = true ; notifyiconMnu = new ContextMenu ( mnuItms ) ;
TrayIcon.ContextMenu = notifyiconMnu ;
//为托盘程序加入设定好的ContextMenu对象
}// public void click ( object sender , System.EventArgs e )
// {
// MessageBox.Show ( "Visual C#编写托盘程序中的事件响应" ) ;
// } public void showmessage ( object sender , System.EventArgs e )
{
MessageBox.Show ( "事件代码还未编写!" ) ;
} public void ExitSelect ( object sender , System.EventArgs e )
{
//隐藏托盘程序中的图标
TrayIcon.Visible = false ;
//关闭系统
this.Close ( ) ;
} //清除程序中使用过的资源
// protected override void Dispose ( )
// {
// base.Dispose ( ) ;
// if ( components != null )
// components.Dispose ( ) ;
// } protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} private void InitializeComponent ( )
{
//
// Tray
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(409, 64);
//this.ControlBox = false;
this.MaximizeBox = false;
//this.MinimizeBox = false;
this.Name = "Tray";
this.ShowInTaskbar = false;
this.Text = "用Visual C#做托盘程序!";
this.DoubleClick += new System.EventHandler(this.Tray_DoubleClick); } static void Main ( )
{
Application.Run ( new Tray ( ) ) ;
} private void Tray_DoubleClick(object sender, System.EventArgs e)
{
MessageBox.Show ( "Visual C#编写托盘程序中的事件响应" ) ;
}
}
}