Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.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_Winforms - Fatal编程技术网

为什么不';我的标签是否以VB.NET格式显示

为什么不';我的标签是否以VB.NET格式显示,vb.net,winforms,Vb.net,Winforms,在阅读了这个问题之后,我编写了一些代码来为xml元素的每个属性创建一个标签 问题是,当我运行项目时,我的表单只显示第一个标签。我已经在即时窗口和调试窗口中进行了检查,所有标签都加载到表单中,但没有显示任何标签。帮忙 下面是加载表单时运行的代码 Dim doc As New XmlDocument() doc.Load("xmlfile") Dim ability As XmlNode = doc.GetElementsByTagName("ability").Item(0) Dim number

在阅读了这个问题之后,我编写了一些代码来为xml元素的每个属性创建一个标签

问题是,当我运行项目时,我的表单只显示第一个标签。我已经在即时窗口和调试窗口中进行了检查,所有标签都加载到表单中,但没有显示任何标签。帮忙

下面是加载表单时运行的代码

Dim doc As New XmlDocument()
doc.Load("xmlfile")
Dim ability As XmlNode = doc.GetElementsByTagName("ability").Item(0)
Dim numberofLabels = ability.Attributes.Count
ReDim labels(numberofLabels)
For counter As Integer = 0 To numberofLabels - 1
    labels(counter) = New Label
    labels(counter).Visible = True
    labels(counter).Text = ability.Attributes.Item(counter).Name
    labels(counter).Location = New System.Drawing.Point(10, 30 + counter * 10)
    Me.Controls.Add(labels(counter))
Next

将新点的原始代码行中的值10更改为更大的值(如40),以便新标签可以在视觉上分开显示:

labels(counter).Location = New System.Drawing.Point(10 + counter, 30 + counter * 40)

您应该使用一些布局管理器来帮助您进行控制定位。手动操作是不值得的。尝试使用
TableLayoutPanel
FlowLayoutPanel
。这两个控件都可以停靠或锚定到父控件,因此所有操作都非常平滑。否则,您需要编写大量定位/调整大小的代码,然后在以后对其进行维护。

实际上并不需要阵列,如果您给它们起一个好名字或给它们加上标签,您可以很容易地在控件集合中找到它们。尝试:
Dim labels(counter)作为新标签
counter*10是一个猜测。这种猜测并不总是奏效,当它太低,所有这些标签相互重叠时,事情就会变得糟糕。这肯定会发生在“视网膜”显示器上。不要猜测,请使用标签的“高度”属性。在添加标签之后。也可以通过将标签添加到FlowLayoutPanel而不是表单来顺利完成定位。还可以尝试将标签的名称设置为类似´“lblXMLAttrib”&counter.ToString´