关闭时代码如下 private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
{
if (trueclose == false)
{
e.Cancel = true;
this.Hide();
}
else
{
Application.Exit();
}
}trueclose是关闭标志,为true时才关闭程序。这样写会导致关不了机?大家帮帮。谢谢了。
{
if (trueclose == false)
{
e.Cancel = true;
this.Hide();
}
else
{
Application.Exit();
}
}trueclose是关闭标志,为true时才关闭程序。这样写会导致关不了机?大家帮帮。谢谢了。
解决方案 »
- 数据库中数据提取不同值
- Winform的画图性能是不是很差?
- 谁有。net里嵌入JavaScript语言的实例啊
- c#引用类型对象的删除问题
- net framework2.0中xmlreader和xmltextreader区别
- 反射中构造函数的参数不能用自定义的类嘛?
- 使用updater application block实现智能客户端的问题
- 简单问题,请帮忙.用C#如何实现字符串的翻转,谢谢!!!!!
- DateTimePicker()的值如何写入数据库?数据库的字段应该是什么类型?能否再读出数据到DateTimePicker()?
- Graphics FillRectangle 很模糊是什么原因
- 怎么让自行绘制的文本支持屏幕取词?
- StringBuilder 转换成 数组 的问题?
{
if(e.CloseReason==CloseReason.UserClosing)
{
e.Cancel = true;
this.Hide();
}
else
{
Application.Exit();
}
} 判断参数e.CloseReason
应该截获关机消息处理之。
改为:
private bool isExitApp = false;
private const int WM_QUERYENDSESSION = 0x0011;
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_QUERYENDSESSION:
isExitApp = true;
break;
default:
base.WndProc(ref m);
break;
} }
private void Form7_FormClosing(object sender, FormClosingEventArgs e)
{
if (!this.isExitApp)
{
e.Cancel = true;
this.WindowState = FormWindowState.Minimized;
this.Hide();
} }
换Environment.Exit(0)试试
if(e.CloseReason==CloseReason.WindowsShutDown)
{
//系统要关闭!
}
{
if(m.Msg == 0x11)
{
// osShutDown是一个在程序一开始定义的一个bool型的变量,用来标记是否截获的是关机消息
osShutDown = true;
}
base.WndProc();
}private void Form1_Closing(object sender, CancelEventArgs e)
{
if( !osShutDown )
{
e.Cancel = true;
this.Hide();
}
}