I just tested which type of code is executed by the WinForms Designer in VS 2008. It seems that the designer is not executing the default constructor anymore. I added a simple thing like this.Text = "foo"; nothing is changed in the designer.
我刚刚测试了VS 2008中WinForms Designer执行的代码类型。似乎设计人员不再执行默认构造函数了。我添加了一个像这样简单的东西.Text =“foo”;设计师没有任何改变。
Did I miss a change between VS 2005/2008? (or SP1)
我错过了VS 2005/2008之间的变化吗? (或SP1)
tia
2 个解决方案
#1
Did you set a breakpoint to see it skip?
你设置了一个断点来看它跳过吗?
If its the first form in the project, instead of starting with "Run", you can F10 (Step Over) to start at the first line of code. From there you can trace the execution.
如果它是项目中的第一个表单,而不是以“Run”开头,则可以从第一行代码开始F10(Step Over)。从那里你可以追踪执行。
.NET 2.0 and above use Partial Classes for windows and web forms. Is it possible that the constructor that is being hit is not default.
.NET 2.0及更高版本使用Windows和Web表单的部分类。被命中的构造函数是否可能不是默认值。
#2
I placed several statements (setting the background, MessageBox.Show, File.WriteAllText,...) into the constructor including System.Diagnostics.Debugger.Break(), but nothing causes any type of response...
我将几个语句(设置背景,MessageBox.Show,File.WriteAllText,...)放入构造函数中,包括System.Diagnostics.Debugger.Break(),但没有任何原因导致任何类型的响应......
Not to misunderstand me, it is the behavior I'd like to have, but I know I had problems in VS 2005 regarding this issue, and I don't find any info about the fact that there is a change in the Winforms Designer.
不要误解我,这是我想要的行为,但我知道我在VS 2005中遇到了关于这个问题的问题,而且我没有找到任何关于Winforms Designer有变化这一事实的信息。
Using the .NET reflector I don't see any additional constructors, but maybe the designer is creating one on-demand, ...
使用.NET反射器我没有看到任何额外的构造函数,但也许设计师正在创建一个按需,...
#1
Did you set a breakpoint to see it skip?
你设置了一个断点来看它跳过吗?
If its the first form in the project, instead of starting with "Run", you can F10 (Step Over) to start at the first line of code. From there you can trace the execution.
如果它是项目中的第一个表单,而不是以“Run”开头,则可以从第一行代码开始F10(Step Over)。从那里你可以追踪执行。
.NET 2.0 and above use Partial Classes for windows and web forms. Is it possible that the constructor that is being hit is not default.
.NET 2.0及更高版本使用Windows和Web表单的部分类。被命中的构造函数是否可能不是默认值。
#2
I placed several statements (setting the background, MessageBox.Show, File.WriteAllText,...) into the constructor including System.Diagnostics.Debugger.Break(), but nothing causes any type of response...
我将几个语句(设置背景,MessageBox.Show,File.WriteAllText,...)放入构造函数中,包括System.Diagnostics.Debugger.Break(),但没有任何原因导致任何类型的响应......
Not to misunderstand me, it is the behavior I'd like to have, but I know I had problems in VS 2005 regarding this issue, and I don't find any info about the fact that there is a change in the Winforms Designer.
不要误解我,这是我想要的行为,但我知道我在VS 2005中遇到了关于这个问题的问题,而且我没有找到任何关于Winforms Designer有变化这一事实的信息。
Using the .NET reflector I don't see any additional constructors, but maybe the designer is creating one on-demand, ...
使用.NET反射器我没有看到任何额外的构造函数,但也许设计师正在创建一个按需,...