【发布时间】:2014-04-04 14:30:52
【问题描述】:
我有一个 UserControl 并希望将它添加到另一个 TabPage 内的 TabPage 但得到 NullReferenceException。
我的代码
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim MyControl As New TimerPanel
Dim Ubicacion As Point
Ubicacion.X = 274
Ubicacion.Y = 100
With MyControl
.Name = "Timer0"
.NombreTimerTxt.Text = "Timer GPS"
.TimerBox.Text = "Timer 00"
.Parent = Me '.TabControl3.TabPages("Timers")
.Location = Ubicacion
.Visible = True
End With
Me.TabControl3.TabPages("Timers").Controls.Add(MyControl) 'Error here
'Me.TabControl1.TabPages("Timers").Controls("Timer0").Location = Ubicacion
End Sub
IDE 说我必须使用“New”这个词来声明它,但我已经在第一行代码中做到了。
另一件事,如果我迭代此代码更改名称和坐标,我将获得独立的控件,或者当我更改一个时都做同样的事情?
我的表单如下所示。
【问题讨论】:
-
您可能没有名为“Timers”的 TabPage。
-
没错,现在我将 TabName 更改为“Timers”,但结果相同。 :(
-
然后试试
Timers.Controls.Add(MyControl)。您的报价:wish to add it to a TabPage Inside another TabPage不准确。 TabPage 不能位于另一个 TabPage 内。也许你的意思是 TabControl?不确定。 -
添加一张图片,让您了解我在 tabPage 中的标签页的含义。正确的顺序是 TabControl->MainTabPage->TabControl->SubTabPage
-
当你尝试我的建议时会发生什么:
Timers.Controls.Add(MyControl)?
标签: vb.net user-controls add vb.net-2010 tabpage