单击退出菜单时,询问是否退出,YES-退出,NO-不退出。那么如何在单击表单的叉叉按钮关闭时也响应这种事件呢?TKS。 if (result==DialogResult.Yes) { this.Close(); //此語句可有可無 } else { e.cancel=true; //取消關閉 } 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在Closing事件中private void childForm_Closing(object sender, System.ComponentModel.CancelEventArgs e){ DialogResult result=MessageBox.Show("确定退出本系统吗?","退出",MessageBoxButtons.YesNo,MessageBoxIcon.Question);if (result==DialogResult.No){ e.e.Cancel = true;} protected override void WndProc(ref Message m) { const int WM_SYSCOMMAND = 0x0112; const int SC_CLOSE = 0xF060; const int scok=0xF061; if (m.Msg == WM_SYSCOMMAND && (int) m.WParam == SC_CLOSE) { // User clicked close button this.Hide(); return; } base.WndProc(ref m); } protected override void WndProc(ref Message m) { const int WM_SYSCOMMAND = 0x0112; const int SC_CLOSE = 0xF060; const int scok=0xF061; if (m.Msg == WM_SYSCOMMAND && (int) m.WParam == SC_CLOSE) { // User clicked close button //把你的那个做个方法,在这调用,然后根据调用结果看是return ,还是继续; return; } base.WndProc(ref m); } 对于jin_xiaolu2000(哦棵)的方法不是太懂,是种什么方法呢?TKS closing事件嘛,e.Cancel=true,就不关闭窗口如果窗口被直接dispose()了,不发生closing事件 我修改后,如下代码,但又出现新情况:点菜单退出时要将“是”按钮点两下才退出(menuItem5的Click事件又发生Closing事件),点“否”却不退出了?!!那应如何改?TKS!private void menuItem5_Click(object sender, System.EventArgs e) { DialogResult result=MessageBox.Show("确定退出本系统吗?","退出", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result==DialogResult.Yes) { this.Close(); } }private void MainFrm_Closing(object sender, System.ComponentModel.CancelEventArgs e) { DialogResult result=MessageBox.Show("确定退出本系统吗?","退出", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result==DialogResult.No) { e.Cancel=true; } } 呵呵private void menuItem5_Click(object sender, System.EventArgs e) { MainFrm_Closing(object sender, System.ComponentModel.CancelEventArgs e) } private void menuItem5_Click(object sender, System.EventArgs e){ Close();//直接调用Close就可以了} 一个关闭的时候,一个触发了CLOSING事件,关闭用我给的那个才行protected override void WndProc(ref Message m) { const int WM_SYSCOMMAND = 0x0112; const int SC_CLOSE = 0xF060; const int scok=0xF061; if (m.Msg == WM_SYSCOMMAND && (int) m.WParam == SC_CLOSE) { // User clicked close button //把你的那个做个方法,在这调用,然后根据调用结果看是return ,还是继续; return; } base.WndProc(ref m); }这个是你点CHACHA 的时候和ALT+F4的时候工作的private void menuItem5_Click(object sender, System.EventArgs e) { DialogResult result=MessageBox.Show("确定退出本系统吗?","退出", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result==DialogResult.Yes) { this.close();//这个就没问题了,去掉你的CLOSING事件,因为那个里面你少了this.close(); }=============================DialogResult result=MessageBox.Show("确定退出本系统吗?","退出", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result==DialogResult.No) { e.Cancel=true;// return; } this.close();//zhege yao you } protected override void WndProc(ref Message m) 重载了消息处理函数这样象你点BACHA 和ALT+F4都是消息处理了 C#是否应该考虑用var作为返回值? "DTSPK.DLL没有依赖项" 用OleDB打开Excel的时候,如果不知道Sheet名如何判断 关于textbox的刷新 关于xml的几个问题,请高手来指教. 请问在winform里面怎样使用用户控件? exchange中如何修改用户的邮箱地址 请问为什么服务端的汉字无法在客户端显示出来? NT下面获得关机权限的API函数怎么用? 图片格式转换问题>>> 回答有分 连接数据库 C#处理jpg图片问题之2,保存jpg图片时如何设定图像品质? 请高手赐教:关于UDPClient使用出现的问题!!!
private void childForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
DialogResult result=MessageBox.Show("确定退出本系统吗?","退出",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);if (result==DialogResult.No)
{
e.e.Cancel = true;
}
protected override void WndProc(ref Message m)
{
const int WM_SYSCOMMAND = 0x0112;
const int SC_CLOSE = 0xF060;
const int scok=0xF061;
if (m.Msg == WM_SYSCOMMAND && (int) m.WParam == SC_CLOSE)
{
// User clicked close button
this.Hide();
return;
}
base.WndProc(ref m);
}
protected override void WndProc(ref Message m)
{
const int WM_SYSCOMMAND = 0x0112;
const int SC_CLOSE = 0xF060;
const int scok=0xF061;
if (m.Msg == WM_SYSCOMMAND && (int) m.WParam == SC_CLOSE)
{
// User clicked close button
//把你的那个做个方法,在这调用,然后根据调用结果看是return ,还是继续;
return;
}
base.WndProc(ref m);
}
点菜单退出时要将“是”按钮点两下才退出(menuItem5的Click事件又发生Closing事件),点“否”却不退出了?!!那应如何改?TKS!
private void menuItem5_Click(object sender, System.EventArgs e)
{
DialogResult result=MessageBox.Show("确定退出本系统吗?","退出",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (result==DialogResult.Yes)
{
this.Close();
}
}
private void MainFrm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
DialogResult result=MessageBox.Show("确定退出本系统吗?","退出",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (result==DialogResult.No)
{
e.Cancel=true;
}
}
private void menuItem5_Click(object sender, System.EventArgs e)
{
MainFrm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
}
{
Close();//直接调用Close就可以了
}
protected override void WndProc(ref Message m)
{
const int WM_SYSCOMMAND = 0x0112;
const int SC_CLOSE = 0xF060;
const int scok=0xF061;
if (m.Msg == WM_SYSCOMMAND && (int) m.WParam == SC_CLOSE)
{
// User clicked close button
//把你的那个做个方法,在这调用,然后根据调用结果看是return ,还是继续;
return;
}
base.WndProc(ref m);
}这个是你点CHACHA 的时候和ALT+F4的时候工作的
private void menuItem5_Click(object sender, System.EventArgs e)
{
DialogResult result=MessageBox.Show("确定退出本系统吗?","退出",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (result==DialogResult.Yes)
{
this.close();//这个就没问题了,去掉你的CLOSING事件,因为那个里面你少了this.close();
}=============================
DialogResult result=MessageBox.Show("确定退出本系统吗?","退出",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (result==DialogResult.No)
{
e.Cancel=true;//
return;
}
this.close();//zhege yao you }
重载了消息处理函数这样象你点BACHA 和ALT+F4都是消息处理了