在 Tab 中配置 UserControl 时出现 NullReferenceException
NullReferenceException when Disposing UserControl in Tab
我正在使用 C# WinForms。
我正在使用一个名为 AGauge 的用户控件。
http://www.codearteng.com/2012/08/agauge-winforms-gauge-control.html
我将控件添加到“设计”视图中的其中一个选项卡页面。
如果我关闭 window 而没有打开包含控件的选项卡页,那么我会得到 NullReferenceException(NullReferenceException 发生在 AGauge.dll -- 对象引用未设置为对象的实例)
如果我打开标签页然后关闭 window,那么一切正常。
执行base.Dispose(disposing)时Dispose()函数出现异常
由于我对 AGauge.dll 中的代码没有任何看法,我不确定该怎么做。我想我可以在标签页打开的 运行 时间创建控件,但这并不理想。
我通过在选项卡控件的 Selected() 函数中创建用户控件解决了这个问题。
private void tb_Panel_Selected(object sender, TabControlEventArgs e)
{
if (myUserControl == null)
{
this.myUserControl = new System.Windows.Forms.AGauge();
...
...
this.Panel.Controls.Add(this.myUserControl)
}
}
我正在使用 C# WinForms。
我正在使用一个名为 AGauge 的用户控件。 http://www.codearteng.com/2012/08/agauge-winforms-gauge-control.html 我将控件添加到“设计”视图中的其中一个选项卡页面。
如果我关闭 window 而没有打开包含控件的选项卡页,那么我会得到 NullReferenceException(NullReferenceException 发生在 AGauge.dll -- 对象引用未设置为对象的实例)
如果我打开标签页然后关闭 window,那么一切正常。
执行base.Dispose(disposing)时Dispose()函数出现异常
由于我对 AGauge.dll 中的代码没有任何看法,我不确定该怎么做。我想我可以在标签页打开的 运行 时间创建控件,但这并不理想。
我通过在选项卡控件的 Selected() 函数中创建用户控件解决了这个问题。
private void tb_Panel_Selected(object sender, TabControlEventArgs e)
{
if (myUserControl == null)
{
this.myUserControl = new System.Windows.Forms.AGauge();
...
...
this.Panel.Controls.Add(this.myUserControl)
}
}