Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从DynamicUserControls VB.NET调用对象_Vb.net_Visual Studio 2010 - Fatal编程技术网

从DynamicUserControls VB.NET调用对象

从DynamicUserControls VB.NET调用对象,vb.net,visual-studio-2010,Vb.net,Visual Studio 2010,喜欢这些论坛,我是VB.NET的初学者,遇到了一些麻烦 这是我的代码片段 'decleare variables Dim vmcount As Integer Dim tabcount As Integer Dim userControl As Control Dim UserControlName As String vmcount = combo_vmcount.SelectedItem tabcount = 1 tab_

喜欢这些论坛,我是VB.NET的初学者,遇到了一些麻烦

这是我的代码片段

    'decleare variables
    Dim vmcount As Integer
    Dim tabcount As Integer
    Dim userControl As Control
    Dim UserControlName As String

    vmcount = combo_vmcount.SelectedItem

    tabcount = 1

    tab_con_vm.TabPages.Clear()


    While (tabcount <= vmcount)

        Dim tabname As New TabPage

        'Load variables
        userControl = New calc_usercontrol_vm

        tabname.Text = "VM" & tabcount

        tabname.Name = "VM" & tabcount

        UserControlName = "UCVM" & tabcount

        userControl.Name = UserControlName

        'actions
        tab_con_vm.TabPages.Add(tabname)


        tabname.Controls.Add(userControl)

         'next
        tabcount = tabcount + 1


    End While
End Sub
”清除变量
将vmcount设置为整数
Dim tabcount为整数
Dim userControl作为控件
Dim UserControlName作为字符串
vmcount=combo_vmcount.SelectedItem
tabcount=1
tab_con_vm.TabPages.Clear()

While(tabcount调用该方法,然后将其添加到页面中,最好在页面生命周期的Init部分。

调用该方法,然后将其添加到页面中,最好在页面生命周期的Init部分。

如果您知道要使用的选项卡的索引

Dim calc_usercontrol As calc_usercontrol_vm = TabPages(index).userControl
或者,如果您不知道索引,您可以使用
IndexOfKey
方法,其中键是tabcontrol的
Name

Dim index as Integer = TabPages.IndexOfKey("TabControlName")

如果您知道要使用的选项卡的索引

Dim calc_usercontrol As calc_usercontrol_vm = TabPages(index).userControl
或者,如果您不知道索引,您可以使用
IndexOfKey
方法,其中键是tabcontrol的
Name

Dim index as Integer = TabPages.IndexOfKey("TabControlName")

虽然这很可能不是解决问题的最佳方法,但我最终创建了一个全局数组,并以此构建了用户控件

' USERCONTROL ARRAY
Public UCVMARRAY(30) As calc_usercontrol_vm






Dim tabcount As Integer

    Dim UCVMARRAYindex As Integer

    Dim userControl As Control 'control variable

    Dim UserControlName As String


    vmcount = combo_vmcount.SelectedItem

    tabcount = 1

    UCVMARRAYindex = 0

    tab_con_vm.TabPages.Clear()


    While (tabcount <= vmcount)

        Dim tabname As New TabPage ' Relook at this to improve the method used. Issue was that new page was not generated on loop.

        'Load variables

        userControl = New calc_usercontrol_vm
        ' loads UC

        tabname.Text = "VM" & tabcount

        tabname.Name = "VM" & tabcount

        UserControlName = "UCVM" & tabcount

        userControl.Name = UserControlName

        UCVMARRAY(UCVMARRAYindex) = userControl 'places it back 

        'actions
        tab_con_vm.TabPages.Add(tabname)

        tabname.Controls.Add(userControl)


        'next
        tabcount = tabcount + 1
        UCVMARRAYindex = UCVMARRAYindex + 1


    End While
End Sub
用户控制数组 作为calc_usercontrol_vm的公共UCVMARRAY(30) Dim tabcount为整数 Dim UCVMARRAYindex为整数 Dim userControl作为控件的控制变量 Dim UserControlName作为字符串 vmcount=combo_vmcount.SelectedItem tabcount=1 UCVMARRAYindex=0 tab_con_vm.TabPages.Clear()
虽然(tabcount虽然这很可能不是解决问题的最佳方法,但我最终创建了一个全局数组,并以此构建了用户控件

' USERCONTROL ARRAY
Public UCVMARRAY(30) As calc_usercontrol_vm






Dim tabcount As Integer

    Dim UCVMARRAYindex As Integer

    Dim userControl As Control 'control variable

    Dim UserControlName As String


    vmcount = combo_vmcount.SelectedItem

    tabcount = 1

    UCVMARRAYindex = 0

    tab_con_vm.TabPages.Clear()


    While (tabcount <= vmcount)

        Dim tabname As New TabPage ' Relook at this to improve the method used. Issue was that new page was not generated on loop.

        'Load variables

        userControl = New calc_usercontrol_vm
        ' loads UC

        tabname.Text = "VM" & tabcount

        tabname.Name = "VM" & tabcount

        UserControlName = "UCVM" & tabcount

        userControl.Name = UserControlName

        UCVMARRAY(UCVMARRAYindex) = userControl 'places it back 

        'actions
        tab_con_vm.TabPages.Add(tabname)

        tabname.Controls.Add(userControl)


        'next
        tabcount = tabcount + 1
        UCVMARRAYindex = UCVMARRAYindex + 1


    End While
End Sub
用户控制数组 作为calc_usercontrol_vm的公共UCVMARRAY(30) Dim tabcount为整数 Dim UCVMARRAYindex为整数 Dim userControl作为控件的控制变量 Dim UserControlName作为字符串 vmcount=combo_vmcount.SelectedItem tabcount=1 UCVMARRAYindex=0 tab_con_vm.TabPages.Clear()
While(tabcount To what objects you reference?To what objects you reference?+1,这是正确的方法(@msarchet,我认为是您的想法,使用了错误的代码)谢谢msarchet!我仍然很难让它工作,很抱歉这么痛苦,你能再详细说明一下吗?@RichardSims你需要详细说明什么?+1,这是正确的方法(@msarchet,我认为你的想法,使用了错误的代码)谢谢msarchet!我还是有点麻烦,很抱歉这么痛苦,你能再详细解释一下吗?@RichardSims你需要详细解释什么?