为什么Me.components什么都没有? [英] Why is Me.components Nothing?
问题描述
我写了一个自定义的ErrorProvider,它为现有的ErrorProvider添加了一些功能(设置了控件BackColor,ErrorCount等)。可以正常工作,但是由于某种原因,它落在了构造函数上:
I have written a custom ErrorProvider which adds some functionality to the existing ErrorProvider (sets control BackColor, ErrorCount etc). This was working find but now for some reason it falls over on the constructor:
_LoginErrorProvider = New ErrorLogErrorProvider(Me.components)
错误是NullReferenceException,它是由Me.components为Nothing引起的。谁能阐明为什么表单的组件集合什么都没有?
The error is a NullReferenceException which is caused by the fact that Me.components is Nothing. Can anyone shed any light on why a form's components collection would be Nothing? The form seems to work fine in every other way!
推荐答案
将表单添加到设计图面时,它会将其添加到表单中。 InitializeComponent函数
when you add a component to the design surface it adds this in the InitializeComponent function
me.components = new System.ComponentModel.Container()
所以只需在自己中添加即可。
so just add this in your self.
或您的
_LoginErrorProvider = New ErrorLogErrorProvider(Me.components)
在InitializeComponent之前被调用
is being called before InitializeComponent
这篇关于为什么Me.components什么都没有?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!