还有个问题:怎么实现windows 的notepad的查找效果,比如我查找到了内容,在父窗体中那个内容处于选中状态,而子窗体又处于Activate状态(因为一旦Activate状态交还给子窗体,父窗体的选中状态就没了)?
期待高人解答
7 个解决方案
#1
将FormClosing的e.Cancel改为true,窗体就不会关闭了
#2
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...
}
}
}
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...
}
}
}
#3
protected override void OnClosing(CancelEventArgs e)
{
base.OnClosing (e);
}
{
base.OnClosing (e);
}
#4
Closing事件中
// 取消关闭
e.Cancel = true;
// 隐藏本窗体
this.Hide();
// 取消关闭
e.Cancel = true;
// 隐藏本窗体
this.Hide();
#5
protected override void OnClosing(CancelEventArgs e)
{
base.OnClosing (e);
}
重写OnClosing事件....OK
{
base.OnClosing (e);
}
重写OnClosing事件....OK
#6
重写OnClosing事件....OK
#7
以上方法都可以。。看你更喜欢哪种。。
#1
将FormClosing的e.Cancel改为true,窗体就不会关闭了
#2
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...
}
}
}
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...
}
}
}
#3
protected override void OnClosing(CancelEventArgs e)
{
base.OnClosing (e);
}
{
base.OnClosing (e);
}
#4
Closing事件中
// 取消关闭
e.Cancel = true;
// 隐藏本窗体
this.Hide();
// 取消关闭
e.Cancel = true;
// 隐藏本窗体
this.Hide();
#5
protected override void OnClosing(CancelEventArgs e)
{
base.OnClosing (e);
}
重写OnClosing事件....OK
{
base.OnClosing (e);
}
重写OnClosing事件....OK
#6
重写OnClosing事件....OK
#7
以上方法都可以。。看你更喜欢哪种。。