NET开发人员。
我正在尝试在表单上放置20个标签并逐行放置(我通过.Top方法执行此操作)。我确信有一种方法可以通过循环更多通用代码20次来编程声明和格式化。
以下是我为第一个标签所做的事情。 在此先感谢您的帮助!
Dim Label1 As New Label
Me.Controls.Add(Label1)
For m = 1 To OutlookManager3.GlobalVariables.SelectedAppointmentsNo
With Label1
.Width = 512
.Height = 18
.Top = subject.Top + subject.Height + m * 6 + (m - 1) * 18 + (m - 1) * 6
.Left = 12
.Text = "label" & m
End With
Next
答案 0 :(得分:1)
你应该将它作为循环中的第一行:
Dim Label1 As New Label
这是最后一行提示你的循环:
Me.Controls.Add(Label1)
示例1
For m = 1 To OutlookManager3.GlobalVariables.SelectedAppointmentsNo
Dim Label1 As New Label
With Label1
.Width = 512
.Height = 18
.Top = subject.Top + subject.Height + m * 6 + (m - 1) * 18 + (m - 1) * 6
.Left = 12
.Text = "label" & m
End With
Me.Controls.Add(Label1)
Next
示例2
For m = 1 To OutlookManager3.GlobalVariables.SelectedAppointmentsNo
Me.Controls.Add(New Label() With {.Width = 512, .Height = 18, .Top = (subject.Top + subject.Height + m * 6 + (m - 1) * 18 + (m - 1) * 6), .Left = 12, .Text = ("label" & m)})
Next
答案 1 :(得分:0)
您可以在循环
中的地方声明语句中使用您的代码对于m = 1到OutlookManager3.GlobalVariables.SelectedAppointmentsNo
Dim Label1 As New Label
With Label1
.Width = 512
.Height = 18
.Top = subject.Top + subject.Height + m * 6 + (m - 1) * 18 + (m - 1) * 6
.Left = 12
.Text = "label" & m
End With
Me.Controls.Add(Label1)
下一步
或者像这样使用面板,但你必须在循环中放置declare语句
或者应该制作标签数组以供将来参考
Dim label(yoursize)As Label 对于m = 1到OutlookManager3.GlobalVariables.SelectedAppointmentsNo
label(m) = new label
label(m).ID="future referece id"
With Label1
.Width = 512
.Height = 18
.Top = subject.Top + subject.Height + m * 6 + (m - 1) * 18 + (m - 1) * 6
.Left = 12
.Text = "label" & m
End With
这样你下次就可以使用了 Me.Controls.Add(Label1的) 下一步