Jam*_*lor 1 c# visual-studio-2008 windows-forms-designer winforms
我最近注意到Visual Studio设计器(我猜它叫做那个)已经删除了我的一些方法句柄.有没有办法阻止设计师这样做?
我的意思是这样的一个例子:我有一个方法,当我的MainForm关闭时称为MainForm_Closing - 基本上是"你想保存更改吗?" 提示.埋在我的Main.designed.cs中的是:
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_Closing);
Run Code Online (Sandbox Code Playgroud)
在与我的MainForm对象相关的部分中.
但是,如果我对MainForm进行任何可视化更改(将控件拖到其上,编辑标签名称,更改图像属性等),则Visual Studio中创建设计器的部分似乎会清除我的自定义代码.
我猜测设计器在编译时被调用来创建designer.cs(因此它可以很容易地编译成IL),因此当然会删除我的自定义句柄.
顺便说一句:我正在生成我的自定义句柄是在IntelliSense的帮助下创建的.例如我输入:
this.FormClosing +=
Run Code Online (Sandbox Code Playgroud)
和IntelliSense建议正确的句柄,并说"按TAB插入").
任何帮助理解这一点(并阻止Visual Studio删除我的句柄)将不胜感激.
如.Designer.cs文件中所述,您不应修改其中的代码Windows Form Designer generated code region,因为每次修改表单时都会自动生成并由Visual Studio覆盖.
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
Run Code Online (Sandbox Code Playgroud)
要向控件的事件添加处理程序,请使用"属性"对话框:
