简体   繁体   English

C#说this.Controls为null,为什么呢?

[英]C# says this.Controls is null, why?

Earlier my code was running nicely.. then I edited some .. did not touch the designer code. 早些时候我的代码运行得很好..然后我编辑了一些..没有碰到设计器代码。

alt text http://img718.imageshack.us/img718/3759/errorstack.jpg 替代文字http://img718.imageshack.us/img718/3759/errorstack.jpg

Why this error is being shown? 为什么显示此错误?

如果这是Windows窗体-您是否从窗体的构造函数中删除了InitializeComponent()行?

Maybe its the label is Null and that's causing the trouble. 也许它的标签是Null,这会引起麻烦。 I'm not that experienced with C# but it could be the case that Controls doesn't except a Null-Pointer. 我对C#并没有那么丰富的经验,但是控件可能只是Null指针而已。

Looks like, at this point in code label1 is not yet initialized. 看起来,此时代码label1尚未初始化。 Whic event handler are you coding this in ? 您在其中使用哪个事件处理程序进行编码? Make sure controls are initialized before using them. 使用控件之前,请确保控件已初始化。 Make sure you are using the controls after InitComplete event. 确保在InitComplete事件之后使用控件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM