我需要做出如同MSN那样的效果:点击程序主窗体右上角的"X"按钮后,程序不退出,而是最小化到系统托盘中,请问“X”按钮所引发的事件是什么?是在form的事件里找么?
语言要求:C#
语言要求:C#
解决方案 »
- winform中,导入一个Excel并把他保存为dataset时,出现“外部表不是预期的格式”???
- Activator.CreateInstance如何传入函数指针
- 页面上实例化表示层时出现这样的错误。
- 用axWindowsMediaPlayer实现播放一个时间段内的mp3,请指教,谢谢!
- [求助]一个简单的动态数组的问题.
- 如何设置只读文本框的前景颜色
- 比較兩個DataTable的數據
- excel表数据定时插入数据到SQL数据库中
- 新手,请教个static变量的问题。
- vpn连接后C#怎么获取VPN分配的IP,本地怎么获取
- 用友EAI U8distribute.dll 引用,导入时提示“没有设置相应的账套或者系统管理设置不正确”
- 求 DrawDibDraw在C#的用法,谁有例子
{
if (!allowExit)
{
e.Cancel = true;
}
base.OnFormClosing(e);
}
{
e.Cancel=true;
this.WindowState=FormWindowState.Minimized; //这是不退出最小化
}
{
this.WindowState = FormWindowState.Minimized;
e.Cancel = true;
}
这样才不退出程序。并且最小化。
我写的程序如下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace MiniToBar
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Resize(object sender, System.EventArgs e)
{//点击“最小化”按钮,使程序缩小至系统托盘。
if (this.WindowState == FormWindowState.Minimized)
{
this.ShowInTaskbar = false;
this.notifyIcon1.Visible = true;
this.Visible = false;
this.notifyIcon1.ContextMenuStrip = contextMenuStrip1;
this.notifyIcon1.BalloonTipText = "请单击,以关闭此气泡";
this.notifyIcon1.BalloonTipTitle = "小程序测试";
this.notifyIcon1.ShowBalloonTip(10);
//this.notifyIcon1.BalloonTipClicked
}
} private void notifyIcon1_MouseDoubleClick_1(object sender, MouseEventArgs e)
{//双击系统托盘的图标,使程序窗体弹出。并且为了防止双击右键也会使窗体弹出,特做以下判断。
if(e.Button == MouseButtons.Left)
{//如果是左键双击,则使窗体恢复。
this.Visible = !this.Visible;
this.WindowState = FormWindowState.Normal;
this.Show();
this.Activate();
this.ShowInTaskbar = true;
}
else
{
//如果是右键双击,不做任何操作。
}
} private void TSMI_Close_Click(object sender, EventArgs e)
{
// Will Close Your Application
this.notifyIcon1.Dispose();
Application.Exit();
} protected override void OnClosing(CancelEventArgs e)
{
e.Cancel = true;
this.ShowInTaskbar = false;
this.notifyIcon1.Visible = true;
this.Visible = false;
this.notifyIcon1.ContextMenuStrip = contextMenuStrip1;
this.notifyIcon1.BalloonTipText = "请单击,以关闭此气泡";
this.notifyIcon1.BalloonTipTitle = "小程序测试";
this.notifyIcon1.ShowBalloonTip(10);
}
}
}红色标识的地方我还不懂,
1.this.WindowState == FormWindowState.Minimized,这句应该是判断窗体现在的状态吧
2.按照MSDN上所说,ShowBalloonTip(10)里的int数值是指定提示气泡存在的时间,以毫秒记,现在应该是存在10毫秒么?为什么我不点这个气泡,这个气泡就一直存在呢?
{
if (!allowExit) //用来表示是否可以关闭窗体的标识
{
e.Cancel = true;
this.ShowInTaskbar=false;
this.WindowState=FormWindowState.Minimized;
}
base.OnFormClosing(e);
}
我在protected override void OnClosing(CancelEventArgs e) 里没有写这句
this.WindowState == FormWindowState.Minimized似乎对程序没有什么影响,
那么楼上的gxingmin和lye2000000_super为什么都加了这句呢?