Click to See Complete Forum and Search --> : Problems Resizing Tab Control with code
BJ
Nov 9th, 1999, 05:00 AM
I have a form with a tab control sstab1. On each tab is a list box and a picture. When I resize them with code they get all screwed up and I can't figure out what's going on. It seems all the items I resize work fine except they appear on what ever tab is showing when the form loads.
Here is my code.
Private Sub Form_Load()
answer = MsgBox("Resize?", vbYesNo, "Resize?")
If answer = vbYes Then
sstab1.Height = 6394
sstab1.Width = 8419
sstab1.Left = 450
sstab1.Top = 1200
Lis0.Width = 3619
Lis0.Height = 4950
Lis0.Top = 1125
Lis0.Left = 4350
Image1.Height = 3056
Image1.Left = 4500
Image1.Top = 1800
Image1.Width = 3056
Lis1.Height = 4950
Lis1.Left = 4350
Lis1.Top = 1125
Lis1.Width = 3619
Image2.Height = 2531
Image2.Left = 300
Image2.Top = 1950
Image2.Width = 3300
End If
End Sub
Does anyone have any suggestions on how to resize this with code?
Thanks
BJ
MartinLiss
Nov 9th, 1999, 05:10 AM
It may be that the problem is not in the resizing, but rather that VB thinks the objects are on the form itself rather than the tab control. I've had that happen to me, especially when I copy an object. You can determine this by looking at the form in notepad. If you can determine that that is the problem, you can correct it in notepad, but make sure to make a backup copy of the form first.
------------------
Marty
BJ
Nov 10th, 1999, 03:00 AM
That was neat. I never knew you could open a form in notepad. Too bad I don't know what to look for though. How can I tell if it is part of the tabcontrol or the form?
Thanks Alot
BJ
MartinLiss
Nov 10th, 1999, 08:11 AM
Here is a simple form that has a tab control with 3 tabs. There is a label on the form and a label on each tab.
VERSION 5.00
Object = "{BDC217C8-ED16-11CD-956C-0000C04E4C0A}#1.1#0"; "TABCTL32.OCX"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 'Windows Default
Begin TabDlg.SSTab SSTab1 ' START OF TAB CONTROL
Height = 1935
Left = 960
TabIndex = 0
Top = 720
Width = 3135
_ExtentX = 5530
_ExtentY = 3413
_Version = 393216
Tab = 2
TabHeight = 520
TabCaption(0) = "Tab 0"
TabPicture(0) = "Form1.frx":0000
Tab(0).ControlEnabled= 0 'False
Tab(0).Control(0)= "lblTab0"
Tab(0).Control(0).Enabled= 0 'False
Tab(0).ControlCount= 1
TabCaption(1) = "Tab 1"
TabPicture(1) = "Form1.frx":001C
Tab(1).ControlEnabled= 0 'False
Tab(1).Control(0)= "lblTab1"
Tab(1).Control(0).Enabled= 0 'False
Tab(1).ControlCount= 1
TabCaption(2) = "Tab 2"
TabPicture(2) = "Form1.frx":0038
Tab(2).ControlEnabled= -1 'True
Tab(2).Control(0)= "lblTab2"
Tab(2).Control(0).Enabled= 0 'False
Tab(2).ControlCount= 1
Begin VB.Label lblTab2
Caption = "I'm on tab 2"
Height = 255
Left = 840
TabIndex = 4
Top = 840
Width = 1575
End
Begin VB.Label lblTab1
Caption = "I'm on tab 1"
Height = 255
Left = -74040
TabIndex = 3
Top = 720
Width = 975
End
Begin VB.Label lblTab0
Caption = "I'm on Tab 0"
Height = 375
Left = -74400
TabIndex = 2
Top = 720
Width = 1095
End
End 'END OF TAB CONTROL
Begin VB.Label lblOnTheForm
Caption = "I'm on the form"
Height = 255
Left = 360
TabIndex = 1
Top = 240
Width = 1695
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub Form_Load()
End Sub
Each control has a Begin and an End blocks. I have added commants at the Begin and End for the tab control, and you can see that the control named lblOnTheForm is outside that block.
------------------
Marty
[This message has been edited by MartinLiss (edited 11-10-1999).]
LG
Nov 10th, 1999, 09:56 AM
Hi,BJ.
Go to property page for tab control. Choose Custom.In a General Tab set Current Tab:0.
Click OK. That's it. Your code will work fine.
Larisa
BJ
Nov 11th, 1999, 09:33 AM
First, Changing the current tab, changes what goes wrong with the tab control. Each time I change the current tab to something new, something different goes wrong with the current tab. So, it has something to do with current tab, but setting it to 0 didn't fix it.
Second, I think my items are on the tab control. So, that must not be the problem. Can I take the code from my form in notepad and copy it into my program and just change the size values to get what I need? Here is what it says. I just don't know what to copy and what to leave out.
Begin TabDlg.SSTab sstab1
Height = 5115
Left = 360
TabIndex = 0
TabStop = 0 'False
Top = 720
Width = 6735
_ExtentX = 11880
_ExtentY = 9022
_Version = 327681
Tabs = 6
Tab = 3
TabHeight = 520
BackColor = 12648447
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
TabCaption(0) = "Breads"
TabPicture(0) = "Form1.frx":0000
Tab(0).ControlEnabled= 0 'False
Tab(0).Control(0)= "List3"
Tab(0).Control(1)= "Image4"
Tab(0).ControlCount= 2
TabCaption(1) = "Meat Dishes"
TabPicture(1) = "Form1.frx":001C
Tab(1).ControlEnabled= 0 'False
Tab(1).Control(0)= "List1"
Tab(1).Control(1)= "Image5"
Tab(1).ControlCount= 2
TabCaption(2) = "Vegetable Dishes"
TabPicture(2) = "Form1.frx":0038
Tab(2).ControlEnabled= 0 'False
Tab(2).Control(0)= "List2"
Tab(2).Control(1)= "Image6"
Tab(2).ControlCount= 2
TabCaption(3) = "Desserts"
TabPicture(3) = "Form1.frx":0054
Tab(3).ControlEnabled= -1 'True
Tab(3).Control(0)= "Image1"
Tab(3).Control(0).Enabled= 0 'False
Tab(3).Control(1)= "List4"
Tab(3).Control(1).Enabled= 0 'False
Tab(3).ControlCount= 2
TabCaption(4) = "Cakes and Pies"
TabPicture(4) = "Form1.frx":0070
Tab(4).ControlEnabled= 0 'False
Tab(4).Control(0)= "Image2"
Tab(4).Control(1)= "List5"
Tab(4).ControlCount= 2
TabCaption(5) = "Miscellaneous"
TabPicture(5) = "Form1.frx":008C
Tab(5).ControlEnabled= 0 'False
Tab(5).Control(0)= "Image3"
Tab(5).Control(1)= "List6"
Tab(5).ControlCount= 2
Sorry If I sound like an idiot,
BJ
[This message has been edited by BJ (edited 11-11-1999).]
LG
Nov 11th, 1999, 10:17 AM
May be I am wrong, but all this code just the description of the properties , that you set at design time. You can check it. Put controls on your tab. Go to File -Print and select Form as Text. I have tried to put all your controls on a Tab and after I finished desigh I set Current Tab to 0, and it works fine. But if I don't do it, then the last tab would be all messed up.
Larisa
MartinLiss
Nov 11th, 1999, 10:40 AM
If you want to, send me a Zip file that contains your project and I'll see if I can figure out what's wrong.
------------------
Marty
Joacim Andersson
Nov 11th, 1999, 02:34 PM
The problem is that even if the ssTab control looks like it has one container per tab it haven't. The control just move the items on the tabs that aren't visible far out to the left. What your code is doing is moving them back so thay are all visible whatever tab is selected.
What you want to do is to first check which tab is active and then move/resize only the controls on that tab.
answer = MsgBox("Resize?", vbYesNo, "Resize?")
If answer = vbYes Then
sstab1.Height = 6394
sstab1.Width = 8419
sstab1.Left = 450
sstab1.Top = 1200
Select case sstab1.Tab
Case 0
Lis0.Width = 3619
Lis0.Height = 4950
Lis0.Top = 1125
Lis0.Left = 4350
Image1.Height = 3056
Image1.Left = 4500
Image1.Top = 1800
Image1.Width = 3056
Case 1
Lis1.Height = 4950
Lis1.Left = 4350
Lis1.Top = 1125
Lis1.Width = 3619
Image2.Height = 2531
Image2.Left = 300
Image2.Top = 1950
Image2.Width = 3300
End Select
End If
Good luck!
------------------
Joacim Andersson
joacim@programmer.net
joacim@yellowblazer.com
www.YellowBlazer.com (http://www.YellowBlazer.com)
BJ
Nov 12th, 1999, 04:57 AM
Joacim you seem to know whats wrong, but at the moment it is still a little over my head.
Martin I tried to email you my program but it didn't go through. You can download it here http://members.xoom.com/vbprogram/TestResize.zip
It's not my program but it is my test code. I tried to make it simple.
Thanks
BJ
BJ
Nov 13th, 1999, 02:03 AM
Martin,
You are a life saver. Probably, no one could have known that was a bug without looking at it. Thanks for taking the time to help me. If you ever need to get into heaven, call me I'll be your reference. Thanks to everyone else also.
BJ
MartinLiss
Nov 13th, 1999, 11:07 AM
I downloaded your code and I have the solution to your problem ;) , but first of all let me say that the behavior of images when moved on a tab control is bizarre to say the least. I think that it is a bug that if you have the time should be reported to MS. In any case here is the soultion: On each tab, cut the listbox and image, draw a frame on the tab, and paste back the listbox and image. The frames will need to be visible, but you could leave the captions blank. You will also need to add sizing logic for the frames. You might also want to change your code as follows:
Dim nIndex As Integer
'resizes the tab control and all of it's objects
answer = MsgBox("Resize?", vbYesNo, "Resize?")
If answer = vbYes Then
For nIndex = 0 To Me.Controls.Count - 1
If TypeOf Me.Controls(nIndex) Is ListBox Then
Me.Controls(nIndex).Move 3300, 500, 3619, 4300
ElseIf TypeOf Me.Controls(nIndex) Is Image Then
Me.Controls(nIndex).Move 300, 1200, 2756, 2981
ElseIf TypeOf Me.Controls(nIndex) Is Frame Then
Me.Controls(nIndex).Move 500, 1000, 7300, 5000
End If
Next nIndex
End If
sstab1.Height = 6394
sstab1.Width = 8419
sstab1.Left = 450
sstab1.Top = 1200
------------------
Marty
[This message has been edited by MartinLiss (edited 11-13-1999).]
MikeGarvin
Dec 10th, 2002, 05:58 PM
Martin, It's me again. I am stuck on this business about resizing controls on an sstb. I use 6 frames on 5 tabs. If I understand correctly, I need in my form_resize event to set each tab so it is in focus, and then set/correct the left property of each control to compensate the -75000? Is this correct?
What I do then is to look to see which Frame I'm on that needs to be resized, then set the focus on the correct tab inside the sstab and finally change the left value which is here fixed at 190.
It's all driving me quite mad, but I would be grateful if you could confirm this. Thanks.
If Ctl.Name = "Frame001" Then
If a >= 0 And a <= 4 Then
Ctl.Container.Tab = a
ElseIf a >= 5 And a <= 9 Then
Ctl.Container.Tab = a - 5
ElseIf a >= 10 And a <= 14 Then
Ctl.Container.Tab = a - 10
ElseIf a >= 15 And a <= 19 Then
Ctl.Container.Tab = a - 15
ElseIf a >= 20 And a <= 24 Then
Ctl.Container.Tab = a - 20
End If
a = a + 1
Ctl.Move 190 * ScaleX, j(1) * ScaleY, j(2) * ScaleX, j(3) * ScaleY
end if
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.