关于Form中右上角的那个关闭按钮的问题?

norikos 2005-03-02 02:53:28
在Form的右上角有三个安钮 最小化 最大化 和关闭
我想问的是那个关闭安钮。在被点击之后。Form的行为到底是怎样的。是否可以改写其行为。比如不让它关闭
...全文
503 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
norikos 2005-03-03
  • 打赏
  • 举报
回复
不知道啊。这个问题好难解决啊
我是老姚 2005-03-02
  • 打赏
  • 举报
回复
是不是要用到API啊?
rainervs 2005-03-02
  • 打赏
  • 举报
回复
norikos 2005-03-02
  • 打赏
  • 举报
回复
Form的问题我已经解决了 谢谢各位
可是ToolBar的还没有解决?有谁有什么好方法?
egxsun 2005-03-02
  • 打赏
  • 举报
回复

private void FrmBillToEntry_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{

e.Cancel = true

}
qiezic 2005-03-02
  • 打赏
  • 举报
回复
关注
机器人 2005-03-02
  • 打赏
  • 举报
回复
在窗体关闭时,Closing 事件发生。在窗体关闭后,将释放在该对象内创建的所有资源并处置该窗体。如果取消此事件,则该窗体保持打开状态。若要取消窗体的关闭操作,请将传递给事件处理程序的 CancelEventArgs 的 Cancel 属性设置为 true。

[Visual Basic]
Private Sub Form1_Closing(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
' Determine if text has changed in the textbox by comparing to original text.
If textBox1.Text <> strMyOriginalText Then
' 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 Then
' Cancel the Closing event from closing the form.
e.Cancel = True
End If ' Call method to save file...
End If
End Sub 'Form1_Closing
End Class 'Form1

[C#]
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...
}
}
}
norikos 2005-03-02
  • 打赏
  • 举报
回复
可是ToolBar没有这个Closing事件。UserControl也没有
adamxx 2005-03-02
  • 打赏
  • 举报
回复
要关不了,就直接重写 Form_Close ,不加任何代码,等于点了按钮不做任何处理
namelx 2005-03-02
  • 打赏
  • 举报
回复
具体的情况是这样的,点击以后windows触发了一个名字叫做wmclose的消息,然后操作系统收到这个消息以后将其关闭,可以不让其关闭,你将它的enable属性设置为false,你如果想让它看起来可以点,却关不了,比较麻烦!
Alexandria 2005-03-02
  • 打赏
  • 举报
回复
点击关闭按钮执行的是Form_Close,你可以在这个事件中操作。
对于Dialog和MessageBox,关闭的效果和Cancel一样,你可以设置DialogResult="Cancel"。
adamxx 2005-03-02
  • 打赏
  • 举报
回复
窗口的关闭按钮是 Form1_closing函数处理的, 你重写这个函数可以解决问题。
其他控件也应该差不多。
norikos 2005-03-02
  • 打赏
  • 举报
回复
补充一下
还有其他控件上也有。比如ToolBar。UserControl等

110,538

社区成员

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

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

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