Private Sub Form_Load()
Dim x(10) As Label
Dim ii As Integer
Dim txtCaption(10) As String
Me.Width = Screen.Width
Me.Height = Screen.Height
Me.Move 0, 0
txtCaption(1) = "dadd "
txtCaption(2) = "的发 "
txtCaption(3) = "dadd "
txtCaption(4) = "dadd"
txtCaption(5) = "dadd"
txtCaption(6) = "dadd"
txtCaption(7) = "dadd"
txtCaption(8) = "dadd"
txtCaption(9) = "风吹走"
txtCaption(10) = "aaaaaaaa000000000000000000 "
Dim Judge_Mod As Integer
For ii = 1 To 10
Judge_Mod = ii Mod 2
Set x(ii) = Me.Controls.Add("vb.label", "x" & ii, Me) '在屏幕上生成lable的关键语句
Debug.Print ii, Len(txtCaption(ii))
With x(ii)
.Caption = ii & " " & txtCaption(ii)
Debug.Print ii, .Width
If Judge_Mod = 1 Then
.Move 100, ii * 300, 2000, 1500
ElseIf Judge_Mod = 0 Then
.Move 5000, (ii - 1) * 300, 2000, 1500
End If
.Visible = True: .AutoSize = True: .BackColor = &HFFFFFF
.Font = "宋体": .AutoSize = True: .FontSize = 10
.BorderStyle = 1
End With
Next ii
End Sub
Dim x(10) As Label
Dim ii As Integer
Dim txtCaption(10) As String
Me.Width = Screen.Width
Me.Height = Screen.Height
Me.Move 0, 0
txtCaption(1) = "dadd "
txtCaption(2) = "的发 "
txtCaption(3) = "dadd "
txtCaption(4) = "dadd"
txtCaption(5) = "dadd"
txtCaption(6) = "dadd"
txtCaption(7) = "dadd"
txtCaption(8) = "dadd"
txtCaption(9) = "风吹走"
txtCaption(10) = "aaaaaaaa000000000000000000 "
Dim Judge_Mod As Integer
For ii = 1 To 10
Judge_Mod = ii Mod 2
Set x(ii) = Me.Controls.Add("vb.label", "x" & ii, Me) '在屏幕上生成lable的关键语句
Debug.Print ii, Len(txtCaption(ii))
With x(ii)
.Caption = ii & " " & txtCaption(ii)
Debug.Print ii, .Width
If Judge_Mod = 1 Then
.Move 100, ii * 300, 2000, 1500
ElseIf Judge_Mod = 0 Then
.Move 5000, (ii - 1) * 300, 2000, 1500
End If
.Visible = True: .AutoSize = True: .BackColor = &HFFFFFF
.Font = "宋体": .AutoSize = True: .FontSize = 10
.BorderStyle = 1
End With
Next ii
End Sub
解决方法
Private Sub Form_Load()
Me.ScaleMode = 3
Debug.Print Me.TextHeight("sdfgf"), Me.TextWidth("DfDdafasddfasdfasdfasdfasff")
End Sub
将以上程序结合使用,不用手动建立n个lable,对于不等长的lable通过计算后,行和列排列整齐.