Is it possible to create tabs in a TabStrip control at runtime. If so, how would you code them? Thanks, Jeremy
Printable View
Is it possible to create tabs in a TabStrip control at runtime. If so, how would you code them? Thanks, Jeremy
The tabstrip control that is by itself, or the tabstrip control within the Windows Common Controls?
VB Code:
For i = 1 To 10 TabStrip1.Tabs.Add , , "Tab #" & i Next
That will add 10 tabs to the tabstrip control, but I don't know how to add them to hte MS Tabbed Dialog control (SSTab).
For each item in my product structure, represented by a treeview, I need to have a tab in my TabStrip. Also, this Product Structure treeview is capable of having new nodes created by drag and drop so when a new node is created, I need a new tab. As far as the tab pages go, I need to have a windows control on each one. Got any ideas. This is my first tabstrip and I'm trying to mimic something I wrote in VBA for excel. Thanks, Jeremy
I'm not using SST. Just FYI.
Whenever you need a new tab, just call the TabStrip.Tabs.Add command to add one, and TabStrip.Tabs.Remove to remove tabs you no longer need.
Ok, I know how to add and remove now but how do I add controls to the tabs? Also, how do I reference information on each tab? I mean, is each tab treated as it's own? You gotta remember, I don't know tabs too well. I'm a dumby to tabs right now. I need to know how to add a tab, reference information on that tab. Make sense? Thanks for your help, Jeremy
You can't add controls to the tabs. They don't act as frames, the way th SSTab control does. You will have to add a frame for each tab and draw your controls inside that frame. If you are loading them at runtime, you will need to load them, then set their parent to the frame control using the SetParent API call.
SSTab1.Tabs = 10Quote:
but I don't know how to add them to hte MS Tabbed Dialog control (SSTab).
SSTab1.TabsPerRow = 10
You lost me. I don't understand.
Last reply wasn't too informative. How can I "draw" a control at runtime? Also, I don't understand Frames either. I know that it doesn't make it any easier for you to help but I need to have some of this explained. Thanks for your help, Jeremy
You have to load controls, not draw them at run time. If you don't know how to do that, then why are you asking how to associate them with tabs when you don't even know how to load them first?
Say you have a frame in a control array named TabFrame(0) and a Tabstrip called TStrip and a textbox in a control array named txtData(0).
VB Code:
Private Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long Dim i As Integer i = i + 1 Load TabFrame(i) Load txtData(i) Tabstrip.Tabs.Add , , "Tab #" & i TabFrame(i).Visible = True SetParent txtData(i).hWnd, TabFrame(i).hWnd txtData(i).Visible = True
You will need more code to make that work, but that is the basics of loading new controls onto the form that are in an array and then setting them inside frame controls. This way when you click the tabs, you can use a select statement in the tab strip's click event to set a certain frame on the form to visible and set every other frame to invisible... very tricky to explain and that's the best I can do.
Thanks for your help. :D
SetParent isn't necessary to use. Most of controls have Container property.
Can you set the container property though? Like Text1.Container = Frame1? I have never tried it like that, I always use SetParent.
Oh, sure - that's what this property is for:
VB Code:
Private Sub Command1_Click() 'the following line will set new parent container for a Texbox Set Text1.Container = Frame1 Text1.Move 120, 240 End Sub
Have you tried that? Gave me an error. Oh wait... ahhhh! The elusive Set statement... I never use set, lol, so I didn't think to use it here. Very good observation IROY :)Quote:
Originally posted by IROY55
Oh, sure - that's what this property is for:
VB Code:
Private Sub Command1_Click() 'the following line will set new parent container for a Texbox Set Text1.Container = Frame1 Text1.Move 120, 240 End Sub
insert a new tabstrip (from ms common controls, not sstab). make sure it has just one tab. below the tabstrip, make a button. in the tab sheet, make a new frame and set its Index property to 0. in the frame, make a new button and set its index prop to 0.
now use this code:
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Sub Command1_Click()
TabStrip1.Tabs.Add , , TabStrip1.Tabs(1).Caption
Load Frame1(Frame1.Count)
With Frame1(Frame1.Count - 1)
.Caption = Frame1.Count
.ZOrder 0
End With
tabHwnd = ObjPtr(TabStrip1.Tabs(TabStrip1.Tabs.Count))
frameHwnd = Frame1(Frame1.Count - 1).hWnd
Load Command2(Command2.Count)
With Command2(Command2.Count - 1)
.Visible = True
.Caption = Command2.Count
End With
SetParent Command2(Command2.Count - 1).hWnd, frameHwnd
End Sub
Private Sub TabStrip1_Click()
currIndex = TabStrip1.SelectedItem.Index - 1
For x = 0 To Frame1.Count - 1
If x <> currIndex Then Frame1(x).Visible = False
Next
Frame1(currIndex).Visible = True
End Sub
KrazyGamer,
as I already pointed out most of controls have Container Property, therefore use of SetParent function is overhead.