想重写Form的关闭事件,要怎么做啊

ppdty 2005-12-21 05:11:23
想重写Form的关闭事件,使他不关闭,而是hide掉,应该重写的是哪个函数呢?
还有个问题:怎么实现windows 的notepad的查找效果,比如我查找到了内容,在父窗体中那个内容处于选中状态,而子窗体又处于Activate状态(因为一旦Activate状态交还给子窗体,父窗体的选中状态就没了)?
期待高人解答
...全文
372 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
止戈而立 2005-12-22
  • 打赏
  • 举报
回复
以上方法都可以。。看你更喜欢哪种。。
uumlwy 2005-12-22
  • 打赏
  • 举报
回复
重写OnClosing事件....OK
Yuna_2z 2005-12-22
  • 打赏
  • 举报
回复
protected override void OnClosing(CancelEventArgs e)
{
base.OnClosing (e);
}

重写OnClosing事件....OK
lbtbox 2005-12-22
  • 打赏
  • 举报
回复
Closing事件中

// 取消关闭
e.Cancel = true;
// 隐藏本窗体
this.Hide();
bobibobi 2005-12-21
  • 打赏
  • 举报
回复
protected override void OnClosing(CancelEventArgs e)
{
base.OnClosing (e);
}
yyw84 2005-12-21
  • 打赏
  • 举报
回复
ms-help://MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfsystemwindowsformsformclassclosingtopic.htm

Form.Closing 事件

private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
// Determine if text has changed in the textbox by comparing to original text.
if (textBox1.Text != strMyOriginalText)
{
// Display a MsgBox asking the user to save changes or abort.
if(MessageBox.Show("Do you want to save changes to your text?", "My Application",
MessageBoxButtons.YesNo) == DialogResult.Yes)
{
// Cancel the Closing event from closing the form.
e.Cancel = true;
// Call method to save file...
}
}
}
wangxnet 2005-12-21
  • 打赏
  • 举报
回复
将FormClosing的e.Cancel改为true,窗体就不会关闭了

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧