问题提出:
有一组控件lable数组(自动生成),需要在1024X728和800X600全屏操作中,变换不同的列,以适应在1024X728和800X600全屏操作,控件Lable的排列.
如在1024X728情况,排4列.在800X600排3列。这就需要,通过计算字符长度,计算字符串在屏幕中所点的象素宽度。请教各位大侠的问题是,如何获得字符串在屏幕中的象素宽度。以下示例程序,能建立n个label控件,现在解决问题的关键是如何根据最大的字符串所占象素宽度,来计算排列宽度。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) = "的饿发啊饿发个和批饿发啊饿不才在的饿了000000000000000000 "
Dim Judge_Mod As IntegerFor ii = 1 To 10
  Judge_Mod = ii Mod 2
  Set x(ii) = Me.Controls.Add("vb.label", "x" & ii, Me)
  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 iiEnd Sub