c#设计器运行什么代码?

时间:2022-08-09 15:50:34

I keep having issues with my code compiling and running fine, yet not loading in the designer. Then I have to debug my visual studio with a second visual studio instance to find the problem. What code is executed by the designer and in what order?

我的代码编译和运行问题一直存在问题,但未在设计器中加载。然后我必须使用第二个可视工作室实例调试我的visual studio以找到问题。设计师执行什么代码以及以什么顺序执行?

2 个解决方案

#1


Hmm. I just noticed that when I view my form named 'MainForm' in the designer actually an object of type System.Windows.Forms.Form is created, not of type MainForm. Some of the code in added controls requires that their parent is a MainForm. When executing the code everything was fine but in the designer it wasn't, because no MainForm is created.

嗯。我只是注意到,当我在设计器中查看名为“MainForm”的表单时,实际上创建了System.Windows.Forms.Form类型的对象,而不是MainForm类型的对象。添加控件中的某些代码要求其父级是MainForm。执行代码时一切都很好,但在设计器中却没有,因为没有创建MainForm。

#2


If you are creating a WinForms application, then it is the code in .designer.cs

如果要创建WinForms应用程序,那么它就是.designer.cs中的代码

#1


Hmm. I just noticed that when I view my form named 'MainForm' in the designer actually an object of type System.Windows.Forms.Form is created, not of type MainForm. Some of the code in added controls requires that their parent is a MainForm. When executing the code everything was fine but in the designer it wasn't, because no MainForm is created.

嗯。我只是注意到,当我在设计器中查看名为“MainForm”的表单时,实际上创建了System.Windows.Forms.Form类型的对象,而不是MainForm类型的对象。添加控件中的某些代码要求其父级是MainForm。执行代码时一切都很好,但在设计器中却没有,因为没有创建MainForm。

#2


If you are creating a WinForms application, then it is the code in .designer.cs

如果要创建WinForms应用程序,那么它就是.designer.cs中的代码