动态控件的排列有关问题
动态控件的排列问题
For a = 1 To 15
Dim NewLabel As New Label
Static Dim LabelID1 As Integer = 0 - 1
LabelID1 += 1
With NewLabel
.Name = "Label" + LabelID1.ToString 'TextBox1.Text
.AutoSize = False
.Size = New System.Drawing.Size(100, 100)
.TabIndex = 0
.Padding = New Padding(5, 5, 5, 5)
.ForeColor = Color.White
.BackColor = Color.Transparent
.Text = "动态生成控件" + LabelID1.ToString
.TextAlign = ContentAlignment.BottomCenter
.Image = My.Resources.wl48
.Cursor = Cursors.Hand
.ImageAlign = ContentAlignment.TopCenter
.Font = New Font("宋体", 11)
' 控件位置
'这里想要的结果是当控件超过屏幕的高时自动排到下一列!!!
.Location = New Point(10, 10 + (LabelID1 * 110))
If .Top + .Height + 50 > Me.Height Then
.Location = New Point(.Left + .Width + 10, 10 + (LabelID1 - LabelID1) * 110)
End If
'运行后超范围的控件都排到了第二列的第一行,各位大侠救命啊!!!
Me.Controls.Add(NewLabel) '添加进from
For a = 1 To 15
Dim NewLabel As New Label
Static Dim LabelID1 As Integer = 0 - 1
LabelID1 += 1
With NewLabel
.Name = "Label" + LabelID1.ToString 'TextBox1.Text
.AutoSize = False
.Size = New System.Drawing.Size(100, 100)
.TabIndex = 0
.Padding = New Padding(5, 5, 5, 5)
.ForeColor = Color.White
.BackColor = Color.Transparent
.Text = "动态生成控件" + LabelID1.ToString
.TextAlign = ContentAlignment.BottomCenter
.Image = My.Resources.wl48
.Cursor = Cursors.Hand
.ImageAlign = ContentAlignment.TopCenter
.Font = New Font("宋体", 11)
' 控件位置
'这里想要的结果是当控件超过屏幕的高时自动排到下一列!!!
.Location = New Point(10, 10 + (LabelID1 * 110))
If .Top + .Height + 50 > Me.Height Then
.Location = New Point(.Left + .Width + 10, 10 + (LabelID1 - LabelID1) * 110)
End If
'运行后超范围的控件都排到了第二列的第一行,各位大侠救命啊!!!
Me.Controls.Add(NewLabel) '添加进from