我想在点击程序右上角的最小化按钮的时候弹出一个对话框? 用windwostate这个属性不行吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用NotifyIcon ,工具箱中有。 自己作一个图标。参考---------------using System ;using System.Drawing ;using System.Collections ;using System.ComponentModel ;using System.Windows.Forms ;using System.Data ;//导入在程序中使用到的名称空间public class Tray : Form{private System.ComponentModel.Container components = null ;private Icon mNetTrayIcon = new Icon ( "Tray.ico" ) ;private NotifyIcon TrayIcon ;private ContextMenu notifyiconMnu ;public Tray(){//初始化窗体中使用到的组件InitializeComponent ( ) ;//初始化托盘程序的各个要素Initializenotifyicon ( ) ;}/* protected override void OnActivated ( EventArgs e ){this.Hide ( ) ;}*/private void Initializenotifyicon ( ){//设定托盘程序的各个属性TrayIcon = new NotifyIcon ( ) ;TrayIcon.Icon = mNetTrayIcon ;TrayIcon.Text = "用Visual C#做托盘程序" + "\n" + "作者:马金虎于2001.12.08" ;TrayIcon.Visible = true ;TrayIcon.Click += new System.EventHandler ( this.click ) ;//定义一个MenuItem数组,并把此数组同时赋值给ContextMenu对象MenuItem [ ] mnuItms = new MenuItem [ 3 ] ;mnuItms [ 0 ] = new MenuItem ( ) ;mnuItms [ 0 ] .Text = "用Visual C#做托盘程序!" ;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 ( ) ;}//清除程序中使用过的资源/*public override void Dispose ( ){base.Dispose ( ) ;if ( components != null )components.Dispose ( ) ;}*/private void InitializeComponent ( ){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 ) ;}static void Main ( ){Application.Run ( new Tray ( ) ) ;}}For more detail, please refer to:http://expert.csdn.net/Expert/TopicView3.asp?id=1137750 在C#的窗口事件里,有一个MinimumSizeChanged事件.双击它就是最小化按钮的时候你要激发的事件代码,如下所示:private void d_main_MinimumSizeChanged(object sender, System.EventArgs e) { }d_main是我窗口的名字. private void Tray_Resize(object sender, System.EventArgs e) { if(this.WindowState.Equals(FormWindowState.Minimized)) { MessageBox.Show(this, "AAAAAAAAAA"); } } Resize 事件,举例如下:private void Form2_Resize(object sender, System.EventArgs e){if (this.WindowState == FormWindowState.Minimized){//Todo:write code here.} 请察看 Visual Studio.net 文档:ms-help://MS.VSCC/MS.MSDNVS.2052/cpref/html/frlrfSystemWindowsFormsFormClassMinimizeBoxTopic.htm 最小化按钮使用户得以将窗口最小化为图标。若要显示最小化按钮,还必须将窗体的 FormBorderStyle 属性设置为下列值之一:FormBorderStyle.FixedSingle、FormBorderStyle.Sizable、FormBorderStyle.Fixed3D 或 FormBorderStyle.FixedDialog。 在运行时最小化窗体会生成 Resize 事件。WindowState 属性反映窗口的当前状态。如果将 WindowState 属性设置为 FormWindowState.Minimized,则窗体是最小化的,而不论对于 MinimizeBox 和 FormBorderStyle 属性什么设置生效。 添加菜单栏,求帮助 请问支付宝接口能否实现延时到账功能 下面这段话错在哪儿 C# 随机变换系统背景桌面 新手请教:关于try/catch块测试字段的问题 .net web 程序中弹出对话框怎么写 如何读取 imagelist中的项 求解压 压缩文件案列 ===== 又引出一个设计上的问题,大家进来看看 ===== 各位大神帮忙看下DLL调用问题 元数据和MSIL的问题? 请问c#做的程序怎样才能很好的释放资源?
参考
---------------
using System ;
using System.Drawing ;
using System.Collections ;
using System.ComponentModel ;
using System.Windows.Forms ;
using System.Data ;
//导入在程序中使用到的名称空间
public class Tray : Form
{
private System.ComponentModel.Container components = null ;
private Icon mNetTrayIcon = new Icon ( "Tray.ico" ) ;
private NotifyIcon TrayIcon ;
private ContextMenu notifyiconMnu ;public Tray()
{
//初始化窗体中使用到的组件
InitializeComponent ( ) ;
//初始化托盘程序的各个要素
Initializenotifyicon ( ) ;
}/* protected override void OnActivated ( EventArgs e )
{
this.Hide ( ) ;
}
*/private void Initializenotifyicon ( )
{
//设定托盘程序的各个属性
TrayIcon = new NotifyIcon ( ) ;
TrayIcon.Icon = mNetTrayIcon ;
TrayIcon.Text = "用Visual C#做托盘程序" + "\n" + "作者:马金虎于2001.12.08" ;
TrayIcon.Visible = true ;
TrayIcon.Click += new System.EventHandler ( this.click ) ;//定义一个MenuItem数组,并把此数组同时赋值给ContextMenu对象
MenuItem [ ] mnuItms = new MenuItem [ 3 ] ;
mnuItms [ 0 ] = new MenuItem ( ) ;
mnuItms [ 0 ] .Text = "用Visual C#做托盘程序!" ;
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 ( ) ;
}
//清除程序中使用过的资源
/*public override void Dispose ( )
{
base.Dispose ( ) ;
if ( components != null )
components.Dispose ( ) ;
}*/private void InitializeComponent ( )
{
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 ) ;}
static void Main ( )
{
Application.Run ( new Tray ( ) ) ;
}}For more detail, please refer to:
http://expert.csdn.net/Expert/TopicView3.asp?id=1137750
private void d_main_MinimumSizeChanged(object sender, System.EventArgs e)
{
}
d_main是我窗口的名字.
{
if(this.WindowState.Equals(FormWindowState.Minimized))
{
MessageBox.Show(this, "AAAAAAAAAA");
}
}
{
if (this.WindowState == FormWindowState.Minimized)
{
//Todo:write code here.
}
ms-help://MS.VSCC/MS.MSDNVS.2052/cpref/html/frlrfSystemWindowsFormsFormClassMinimizeBoxTopic.htm 最小化按钮使用户得以将窗口最小化为图标。若要显示最小化按钮,还必须将窗体的 FormBorderStyle 属性设置为下列值之一:FormBorderStyle.FixedSingle、FormBorderStyle.Sizable、FormBorderStyle.Fixed3D 或 FormBorderStyle.FixedDialog。
在运行时最小化窗体会生成 Resize 事件。WindowState 属性反映窗口的当前状态。如果将 WindowState 属性设置为 FormWindowState.Minimized,则窗体是最小化的,而不论对于 MinimizeBox 和 FormBorderStyle 属性什么设置生效。