Results 1 to 19 of 19

Thread: TabStrip Tabs at run time

  1. #1

    Thread Starter
    Fanatic Member JCScoobyRS's Avatar
    Join Date
    Oct 2002
    Location
    Some Mountain in Colorado
    Posts
    677

    TabStrip Tabs at run time

    Is it possible to create tabs in a TabStrip control at runtime. If so, how would you code them? Thanks, Jeremy

  2. #2
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    The tabstrip control that is by itself, or the tabstrip control within the Windows Common Controls?
    <removed by admin>

  3. #3
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    VB Code:
    1. For i = 1 To 10
    2. TabStrip1.Tabs.Add , , "Tab #" & i
    3. 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).
    <removed by admin>

  4. #4

    Thread Starter
    Fanatic Member JCScoobyRS's Avatar
    Join Date
    Oct 2002
    Location
    Some Mountain in Colorado
    Posts
    677

    What I need

    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

  5. #5

    Thread Starter
    Fanatic Member JCScoobyRS's Avatar
    Join Date
    Oct 2002
    Location
    Some Mountain in Colorado
    Posts
    677

    No SST

    I'm not using SST. Just FYI.

  6. #6
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    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.
    <removed by admin>

  7. #7

    Thread Starter
    Fanatic Member JCScoobyRS's Avatar
    Join Date
    Oct 2002
    Location
    Some Mountain in Colorado
    Posts
    677

    Ok

    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

  8. #8
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    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.
    <removed by admin>

  9. #9
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    but I don't know how to add them to hte MS Tabbed Dialog control (SSTab).
    SSTab1.Tabs = 10
    SSTab1.TabsPerRow = 10
    Roy

  10. #10

    Thread Starter
    Fanatic Member JCScoobyRS's Avatar
    Join Date
    Oct 2002
    Location
    Some Mountain in Colorado
    Posts
    677

    I'm lost.

    You lost me. I don't understand.

  11. #11

    Thread Starter
    Fanatic Member JCScoobyRS's Avatar
    Join Date
    Oct 2002
    Location
    Some Mountain in Colorado
    Posts
    677

    Question I know, I'm dumb

    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

  12. #12
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    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:
    1. Private Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    2. Dim i As Integer
    3. i = i + 1
    4. Load TabFrame(i)
    5. Load txtData(i)
    6. Tabstrip.Tabs.Add , , "Tab #" & i
    7. TabFrame(i).Visible = True
    8. SetParent txtData(i).hWnd, TabFrame(i).hWnd
    9. 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.
    <removed by admin>

  13. #13

    Thread Starter
    Fanatic Member JCScoobyRS's Avatar
    Join Date
    Oct 2002
    Location
    Some Mountain in Colorado
    Posts
    677

    Thanks

    Thanks for your help.

  14. #14
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    SetParent isn't necessary to use. Most of controls have Container property.
    Roy

  15. #15
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    Can you set the container property though? Like Text1.Container = Frame1? I have never tried it like that, I always use SetParent.
    <removed by admin>

  16. #16
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    Oh, sure - that's what this property is for:
    VB Code:
    1. Private Sub Command1_Click()
    2.     'the following line will set new parent container for a Texbox
    3.     Set Text1.Container = Frame1
    4.     Text1.Move 120, 240
    5. End Sub
    Roy

  17. #17
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    Originally posted by IROY55
    Oh, sure - that's what this property is for:
    VB Code:
    1. Private Sub Command1_Click()
    2.     'the following line will set new parent container for a Texbox
    3.     Set Text1.Container = Frame1
    4.     Text1.Move 120, 240
    5. 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
    <removed by admin>

  18. #18
    Lively Member
    Join Date
    Nov 2001
    Location
    i live where you don't
    Posts
    76
    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

  19. #19
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    KrazyGamer,
    as I already pointed out most of controls have Container Property, therefore use of SetParent function is overhead.
    Roy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width