BUG: Tab Control Does Not Initialize Correctly from Load Event Using Control Array (214830)
The information in this article applies to:
- Microsoft Visual Basic Learning Edition for Windows 5.0
- Microsoft Visual Basic Learning Edition for Windows 6.0
- Microsoft Visual Basic Professional Edition for Windows 5.0
- Microsoft Visual Basic Professional Edition for Windows 6.0
- Microsoft Visual Basic Enterprise Edition for Windows 5.0
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
This article was previously published under Q214830 SYMPTOMS
The Tab Control is not able to initialize correctly when placing controls that are members of a control array on separate tabs from the load event of the form on which the Tab Control was placed. All the controls are drawn on a single tab instead of on the tabs for which they were intended. This problem occurs in Visual Basic 6.0 and Visual Basic 5.0 with service pack 2 or later.
RESOLUTIONMethod 1
To work around this problem, move the code that places controls on the tabs from the load event to the Activate event of the form. Use a global flag to determine if the Activate event was fired without unloading the form. For example, use the sample project created in "Steps to Reproduce Behavior" below and follow these steps:
- Move the code listed in step 5 from the Load event to the Activate event of Form1.
- Modify the code in the Activate event by replacing it with the following:
Dim i as integer
If ActivateFlag = False Then
For i = 1 To 3
SSTab1.Tab = i - 1
Load Text1(i)
Set Text1(i).Container = SSTab1
Text1(i).Top = i * (SSTab1.TabHeight + 100)
Text1(i).Left = i * 200
Text1(i).Visible = True
Next i
ActivateFlag = True
End If
- From the Project menu, add a Standard Module (Module1) to the project and add the following line of code to Module1:
Public ActivateFlag as Boolean
- Place the following line of code in the Unload event of Form1:
ActivateFlag = False
- Run the application and note that all members of the TextBox control array are displayed on the correct tab.
Method 2
Another workaround is to place the control loading code in a global procedure. Call this procedure before calling the Show method for the form containing the tab control. For example:
- Follow the steps 1 through 4 in "Steps to Reproduce Behavior" below.
- From the Project menu, add a (BAS) Module to the project and copy and paste the following code to General Declarations area of Module1:
Sub MyTabSetup()
Dim i As Integer
With Form1
For i = 1 To 3
.SSTab1.Tab = i - 1
Load .Text1(i)
Set .Text1(i).Container = .SSTab1
.Text1(i).Top = i * (.SSTab1.TabHeight + 100)
.Text1(i).Left = i * 200
.Text1(i).Visible = True
Next i
End With
End Sub
- Create a Sub Main procedure to be set as Startup object for the project by adding the following code to Module1:
Sub Main()
MyTabSetup
Form1.Show
End Sub
- From the Project menu, select Project1 Properties, and on the General tab, select Sub Main as the Startup Object.
- Run the application and there should be one TextBox on each tab.
- The procedure can also be called before the Show method of the form when ever the form needs to be displayed. For example, if the form was closed and needed to be shown from the click event of a CommandButton, simply place the following code in the click event of the CommandButton:
Private Sub Command1_Click()
MyTabSetup
Form1.Show
End Sub
STATUSMicrosoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
Modification Type: | Major | Last Reviewed: | 5/13/2003 |
---|
Keywords: | kbBug kbpending kbTabCtrl KB214830 |
---|
|