VSTO插件表单关闭处理程序
本文关键字:处理 程序 插件 表单 VSTO | 更新日期: 2023-09-27 17:51:00
我有一个outlook 2013的VSTO插件。我试图注册一个事件与窗体关闭事件的事件处理程序。
这是我的代码从类Form1:
public delegate void MyEventHandler();
private event MyEventHandler Closing;
private void OtherInitialize()
{
this.Closing += new MyEventHandler(this.Form1_Closing);
}
也来自类Form1:
public Form1()
{
InitializeComponent();
OtherInitialize();
}
private void Form1_Closing(object sender, CancelEventArgs e)
{
// Not sure what to put here to make the application exit completely
// Looking for something similar to Pytthon's sys.exit() or
// Applicaton.Exit() in Forms Applicatons, I tried
// Applicaton.Exit() it did not work
}
当我运行这个时,我得到错误和警告:
警告:
Form1.Closing hides inherited member System.Windows.Forms.Form.Closing. Use the new keyword if hiding was intended
错误:
No overload for Form1_Closing matches delegate System.EventHandler
这些错误/警告是什么意思?我怎样才能正确地注册Form1_Closing事件处理程序,当窗体关闭无论是X按钮或form. close()现在我能够调用form. close(),但它似乎没有触发Form1_Closing事件。
不需要声明关闭事件,因为父类提供了开箱即用的事件。此外,您可以简单地设置事件处理程序,而无需声明委托类(最新的。net版本):
public Form1()
{
InitializeComponent();
OtherInitialize();
}
private void OtherInitialize()
{
Closing += Form1_Closing;
}
private void Form1_Closing(object sender, CancelEventArgs e)
{
// Not sure what to put here to make the application exit completely
// Looking for something similar to Pytthon's sys.exit() or
// Applicaton.Exit() in Forms Applicatons, I tried
// Applicaton.Exit() it did not work
}