在运行时Windows应用程序vb.net中挂载现有的usercontrol [英] Mount existing usercontrol in runtime windows application vb.net

查看:83
本文介绍了在运行时Windows应用程序vb.net中挂载现有的usercontrol的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在这里有一个问题.
这是什么,

-我有一个名为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>

推荐答案

两件事.

调用控件UserControl是一个非常糟糕的主意,因为该控件已在.NET Framework中用作类名.您的控件应被称为更具描述性的内容.

您忘记了将新创建的contorl实例添加到其父容器的Controls集合中,就像您添加的选项卡一样.
Two things.

It''s a REALLY bad idea to call your control UserControl as that is already used as a class name in the .NET Framework. Your control should be called something a bit more descriptive.

You forgot to add the newly created contorl instance to the Controls collection of its parent container, like the tabpage you added.


哦,这是旧文章.
并且我已经正确地解决了它(从编程视图和用户视图,当然是^^)

下次我将发布解决方法.

我最近忙于制作手机游戏(并在这里提问^^).我致歉.

谢谢
oh, this''s old post.
and I''ve solved it properly (from programming view and user view of course ^^)

Next time I''ll post how I solved it.

I''m too busy of making mobile game (and asking question here^^) lately. My appologize.

Thanks


这篇关于在运行时Windows应用程序vb.net中挂载现有的usercontrol的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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