vb 关于 “动态生成控件”,与 “滚动条” 的问题
我在一容器中,用动态生成控件的方法,创建了1024个控件。
由于数量太多,需要做个滚动条方便查看。
现在就是不知道这个滚动条与控件该怎么处理了。
[解决办法]
大概这样吧,给一个我写的简单的代码给参考一下:
Form1的代码:新建一个txt,保存为frm后缀
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 5175
ClientLeft = 60
ClientTop = 450
ClientWidth = 4455
LinkTopic = "Form1"
ScaleHeight = 5175
ScaleWidth = 4455
StartUpPosition = 3 '窗口缺省
Begin VB.PictureBox Picture1
Height = 4935
Left = 120
ScaleHeight = 4875
ScaleWidth = 4155
TabIndex = 0
Top = 120
Width = 4215
Begin VB.TextBox Text1
Height = 270
Index = 9
Left = 960
TabIndex = 21
Top = 4500
Width = 2655
End
Begin VB.TextBox Text1
Height = 270
Index = 8
Left = 960
TabIndex = 19
Top = 3960
Width = 2655
End
Begin VB.TextBox Text1
Height = 270
Index = 7
Left = 960
TabIndex = 17
Top = 3480
Width = 2655
End
Begin VB.TextBox Text1
Height = 270
Index = 6
Left = 960
TabIndex = 15
Top = 3000
Width = 2655
End
Begin VB.TextBox Text1
Height = 270
Index = 5
Left = 960
TabIndex = 13
Top = 2520
Width = 2655
End
Begin VB.TextBox Text1
Height = 270
Index = 4
Left = 960
TabIndex = 11
Top = 2040
Width = 2655
End
Begin VB.TextBox Text1
Height = 270
Index = 3
Left = 960
TabIndex = 9
Top = 1560
Width = 2655
End
Begin VB.TextBox Text1
Height = 270
Index = 2
Left = 960
TabIndex = 7
Top = 1080
Width = 2655
End
Begin VB.TextBox Text1
Height = 270
Index = 1
Left = 960
TabIndex = 5
Top = 600
Width = 2655
End
Begin VB.TextBox Text1
Height = 270
Index = 0
Left = 960
TabIndex = 3
Top = 180
Width = 2655
End
Begin VB.VScrollBar VScroll1
Height = 4875
Left = 3900
TabIndex = 1
Top = 0
Width = 255
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "项目1:"
Height = 180
Index = 9
Left = 240
TabIndex = 20
Top = 4560
Width = 630
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "项目1:"
Height = 180
Index = 8
Left = 240
TabIndex = 18
Top = 4020
Width = 630
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "项目1:"
Height = 180
Index = 7
Left = 240
TabIndex = 16
Top = 3540
Width = 630
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "项目1:"
Height = 180
Index = 6
Left = 240
TabIndex = 14
Top = 3060
Width = 630
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "项目1:"
Height = 180
Index = 5
Left = 240
TabIndex = 12
Top = 2580
Width = 630
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "项目1:"
Height = 180
Index = 4
Left = 240
TabIndex = 10
Top = 2100
Width = 630
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "项目1:"
Height = 180
Index = 3
Left = 240
TabIndex = 8
Top = 1620
Width = 630
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "项目1:"
Height = 180
Index = 2
Left = 240
TabIndex = 6
Top = 1140
Width = 630
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "项目1:"
Height = 180
Index = 1
Left = 240
TabIndex = 4
Top = 660
Width = 630
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "项目1:"
Height = 180
Index = 0
Left = 240
TabIndex = 2
Top = 240
Width = 630
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim AryItem(1, 1023) As String
Dim vI As Long
Private Sub Form_Load()
For vI = 0 To 1023
AryItem(0, vI) = "项目" & vI
AryItem(1, vI) = "第" & vI & "项"
Next
For vI = 0 To 9
Label1(vI).Caption = AryItem(0, vI)
Text1(vI).Text = AryItem(1, vI)
Next
VScroll1.Min = 0
VScroll1.Max = 1014
VScroll1.Value = 0
VScroll1.LargeChange = 10
End Sub
Private Sub Text1_Change(Index As Integer)
AryItem(1, VScroll1.Value + Index) = Text1(Index).Text
End Sub
Private Sub VScroll1_Change()
For vI = 0 To 9
Label1(vI).Caption = AryItem(0, VScroll1.Value + vI)
Text1(vI).Text = AryItem(1, VScroll1.Value + vI)
Next
End Sub
Type=Exe
Form=Form1.frm
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\WINDOWS\system32\stdole2.tlb#OLE Automation
Startup="Form1"
Command32=""
Name="工程1"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="KuEr"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1
[MS Transaction Server]
AutoRefresh=1