错误 - 未将对象引用设置为对象的实例 [英] Error - Object reference not set to an instance of an object

查看:89
本文介绍了错误 - 未将对象引用设置为对象的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个相当大的表格,有很多标签和盒子等等。有些标签可以改变他们的文字点击。


加载看似没问题。但是,当我单击标签时,表单会因上述错误而崩溃。


标签在设计视图中可见。它在文档大纲中正确列出。然而它声称它不知道它。我已经尝试消除所有负载事件并且已经注释掉了很多其他类但无济于事。相同的代码在一个非常非常基本的表单上工作正常,所以我认为它被另一个类绕过了。


是否有一些已知问题/变通方法/代码用于此类事情一个复杂的形式?我可以在加载表单之后等待很长时间,然后再触发文本更改仍然会失败。


标签更改的代码如下。

Hi

I have a fairly large form with many labels and boxes etc. Some labels are set to alter their text onclick.

It loads seemingly ok. However when I click the label the form crashes with the aforementioned error.

The label is visible in design view. It is listed correctly in the document outline. Yet it is claimed it doesn''t know about it. I''ve tried eliminating all ''load'' events and have commented out alot of other classes but to no avail. The same code works ok on a very, very basic form so I assume it is getting bypassed by another class.

Is there some known issue/workaround/code for this type of thing for a complex form? I can wait ages after loading the form before triggering the text change and it still fails.

The code for the Label change is as follows.

展开 | 选择 | Wrap | 行号

推荐答案

robertybob,我不确定这是不是你的问题,但在VB6中没有标签的文本属性。文本框具有文本属性,标签具有标题属性。
robertybob, I''m not sure if this is your issue or not but in VB6 there is no Text property of a label. Text boxes have the Text property, Labels have a Caption property.


Hi Mikkeee,


我认为这可能是在错误的论坛,因为我正在使用Visual Basic 2010 - 我会看看我是否可以移动它。


一切顺利。
Hi Mikkeee,

I think this might be in the wrong forum as I''m using Visual Basic 2010 - I''ll see if I can move it over.

All the best.


robertybob,你到底想要完成什么?你是vb.net的新手(也许来自vb6世界)?我问的原因是我相信你可能会使用更多的VB6思维方式来解决这个问题。在dotnet中,您可以为同一事件分配许多类似控件,并从sender属性中获取传入控件。看看下面的示例。我在表单上有三个标签,点击它时会更改。您需要做的就是在Handles语句之后包含其他控件事件。这样你每次都不需要经历表单控件集合。

robertybob, what exactly are you trying to accomplish? Are you new to vb.net (maybe coming from the vb6 world)? The reason I ask is that I believe you might be going about this the wrong way using more of a VB6 mindset. In dotnet you can assign many like controls to the same event and grab the incoming control from the sender property. Take a look at my sample below. I have three labels on a form and they will change when clicking on it. All you need to do is include additional control events after the Handles statement. This way you won''t need to go through the forms control collection every time.

展开 | 选择 | Wrap | 行号


这篇关于错误 - 未将对象引用设置为对象的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆