问题描述
我在这里有一个问题.
这是什么,
-我有一个名为ucDataUser.ascx的用户控件
-我有一个公共子目录,可以在tabcontorl中创建新的标签页
-标签页应动态包含ucDataUser
< pre lang ="HTML">我尝试过的代码:
< pre ="vb">公共子mainTabBaru(ByVal namaTab作为字符串)
昏暗的c作为新的TabPage
c.Name = namaTab
如果mainForm.TabControl1.TabPages.ContainsKey(namaTab)然后
mainForm.TabControl1.SelectTab(namaTab)
其他
mainForm.TabControl1.TabPages.Add(c)
c.Text = namaTab
Dim nama As String
nama ="uc" +修剪(namaTab)
昏暗b作为新的UserControl
b.Name =娜玛
b.父母= c
b.Dock = DockStyle.Fill
b.Show()
如果结束
结束Sub</pre>
该代码上的namaTab变量应根据我需要在标签页上显示的用户控件进行动态更改.
但是结果总是将代码< code> Dim b中的新空用户控件作为新的usercontrol</code>.
</pre>
Hi,
I have a question here.
Here''s what,
- I have a usercontrol called ucDataUser.ascx
- I have a public sub to create new tabpage in tabcontorl
- The tabpage should be dynamically consist of ucDataUser
<pre lang="HTML">The code that I''d tried :
<pre="vb">Public Sub mainTabBaru(ByVal namaTab As String)
Dim c As New TabPage
c.Name = namaTab
If mainForm.TabControl1.TabPages.ContainsKey(namaTab) Then
mainForm.TabControl1.SelectTab(namaTab)
Else
mainForm.TabControl1.TabPages.Add(c)
c.Text = namaTab
Dim nama As String
nama = "uc" + Trim(namaTab)
Dim b As New UserControl
b.Name = nama
b.Parent = c
b.Dock = DockStyle.Fill
b.Show()
End If
End Sub</pre>
namaTab variable on that code should be dynamically change according to the usercontrol that I need to show on the tabpage.
But the result always new empty usercontrol from the code <code>Dim b as new usercontrol</code>.
How''s that happen and how to fix it?</pre>
推荐答案
这篇关于在运行时Windows应用程序vb.net中挂载现有的usercontrol的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!