Я создал следующие вспомогательные методы для решения этой проблемы:
Private Sub ResizeTabControls()
Dim c As Control
Dim lb As ListBox
For Each c In Me.Controls
If TypeOf c Is ListBox Then
Set lb = c
If InStr(1, lb.Name, "list3") > 0 Then
lb.Height = TabClientHeight
lb.Top = TabTabsHeight
End If
End If
Next
End Sub
Private Function TabClientHeight() As Single
TabClientHeight = SSTab1.Height - TabTabsHeight
End Function
Private Function TabTabsHeight() As Single
Dim Number As Single
Dim TabRows As Integer
'calculate rows rounded up
Number = SSTab1.Tabs / SSTab1.TabsPerRow
If Number - Int(Number) = 0 Then
TabRows = Int(Number)
Else
TabRows = Int(Number + 1)
End If
'calculate height
TabTabsHeight = SSTab1.TabHeight * TabRows
End Function
При наличии этих кодов ваш существующий код выглядит следующим образом:
Private Sub Command5_Click()
Static Xx As Integer
Dim x As Integer
Dim txt As ListBox
Xx = Xx + 1
Text4.Text = Xx
For x = 0 To List2.ListCount - 1
If InStr(List2.List(x), "download") Then
SSTab1.Tabs = Text4.Text
SSTab1.Tab = Text4.Text - 1 'controls get added to the active tab
SSTab1.TabCaption(Text4.Text - 1) = "keywords" & " " & Text4.Text - 1
Set txt = Me.Controls.Add("VB.ListBox", "list3" & Text4.Text, Me)
Set txt.Container = SSTab1
txt.Visible = True
'txt.IntegralHeight = False 'can only be set thru the designer
txt.Height = TabClientHeight 'exact height needs IntegralHeight = False
txt.Width = 7575
txt.Left = 180
txt.Top = TabTabsHeight
txt.AddItem List2.List(x)
End If
Next x
'resize existing controls whenever a new row of tabs is created
If SSTab1.Tabs > 1 And SSTab1.Tabs Mod SSTab1.TabsPerRow = 1 Then
ResizeTabControls
End If
End Sub