找不到任何原因!删除Closing事件,后写入: public Form1()//Your WinForm Constructor { InitializeComponent(); this.FormClosing += new FormClosingEventHandler(Form1_FormClosing); }private void Form1_FormClosing(object sender, FormClosingEventArgs e) { throw new Exception("The method or operation is not implemented."); }
this.FormClosing += new FormClosingEventHandler(Form1_FormClosing); ~~~~~~~~~~~~~~~~~~~这是2.0的吧1.1中对应的就是Closing
那注册事件在哪儿看,我在另一页面实现closing 没有问题
如果要注册,在哪儿操作,谢谢
this.Closing +=new CancelEventHandler(Form1_Closing);在类中加入:
private void Form1_Closing(object sender, CancelEventArgs e)
{
MessageBox.Show("dfas");
}
“我在另一页面实现closing 没有问题”,这样的话应该是没有太多意外的吧
但是在这页面就是不能实现,我单步调试了,都没有走到
closing事件中,为什么呢?
该怎么把closing事件注册到form上呢?
[email protected]
public Form1()//Your WinForm Constructor
{
InitializeComponent();
this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);
}private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
throw new Exception("The method or operation is not implemented.");
}
~~~~~~~~~~~~~~~~~~~这是2.0的吧1.1中对应的就是Closing
你选中窗口后,到属性窗口的事件中,把Closing事件清空掉,然后双击加一个一试就OK,不行就重启动一次,编译器确实有时会出现这种怪现象。
怎么重载wndProc法,能写个大概吗?
{
System.Console.WriteLine(m.Msg.ToString());
if (m.Msg == 130) // 消息的值不知道,
{
// closing operator
MessageBox.Show("Closing is canceled");
return;
}
base.WndProc (ref m);
}
再跟蹤運行一下看下能不能响应
我试过,我指向了WM_DESTROY 0x0002
也是不行,它只能响应主窗体
只有主窗体关闭后,它才会响应
我用的是dotnetMagic 中的Docking窗体,而我要关的也是它,我想
得知该窗体是否存在
你要关闭的窗体没有真正的关闭
所以不会执行closing事件,只要验证它是否可见,就行了
在主窗体中
private Content cA;
cA必须唯一,不能有重名的局部实例对象
if(cA.Visible==false)
{
执行A;
}
else
{
执行B;
}