Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.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
Vb.net 如何在类被实例化后创建公共变量?_Vb.net - Fatal编程技术网

Vb.net 如何在类被实例化后创建公共变量?

Vb.net 如何在类被实例化后创建公共变量?,vb.net,Vb.net,使用Winforms和VS 2012: 我需要创建一个新的项目类,但创建该类时,我不知道需要多少项目。只有在它被创建并确定大小之后,我才知道我需要多少。那么,在类被实例化之后,我可以创建更多吗 例如: 我正在创建一个面板,在该面板中我将有一些子面板。但是我不知道有多少孩子。它将基于父面板的高度 Public Class parent_panel() Public panel_1 as new panel Public Sub New() with panel_1

使用Winforms和VS 2012:

我需要创建一个新的项目类,但创建该类时,我不知道需要多少项目。只有在它被创建并确定大小之后,我才知道我需要多少。那么,在类被实例化之后,我可以创建更多吗

例如:

我正在创建一个面板,在该面板中我将有一些子面板。但是我不知道有多少孩子。它将基于父面板的高度

Public Class parent_panel()

   Public panel_1 as new panel

   Public Sub New()

     with panel_1
       .parent = Me
       .location = new point(0,0)
     end with

   End Sub

End Class

Public Class main()

   Private p_panel as new parent_panel

   Public Sub new()

     with p_panel
       .parent = Main
       .location = new point(0,0)
       .width = Main.width
       .height = Main.height
     end with
     ' now that I know the height of this panel, I need to go back and add
 '"panel_2", "panel_3" and so on to parent_panel until I fill the height of this panel.

      End Sub

End Class

正如所建议的,您不会为每个子级使用离散变量,因为编译后无法添加变量。您可以使用一个变量存储单个对象,然后该对象可以包含多个对象,即数组或集合。如果大小将设置一次并保持不变,则应使用数组,但如果可能会更改,则应使用集合,即ListOf面板。

您可以有一个parent_面板的成员,它是ListOf面板。我将如何具体操作?这将在何时创建?我该如何向列表中添加更多内容并使其公开?请尝试TableLayoutPanel谢谢,但TableLayoutPanel无法满足我的需要。我需要一个非常具体的方式来处理面板及其对象。