CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2001
    Posts
    6,332

    SSTab Exposed, demystified, and beaten with a stick

    While answering a question in a recent thread, I ran into something interesting. I had not used the SSTab control much, but anyone who has looked into it should know that it only has one hWnd. This means that all the controls you place in it are in the same window, no matter what tab they are on. Adding tabs and/or controls at runtime can be a bit confusing.

    So, you may be asking yourself; If the SSTab control has one window for all the tabs/controls, where do controls disappear to when you click a tab?. Before I played around with it, I thought there might be other windows, but that they are just not exposed somehow.

    As it turns out, the method for showing only those controls which are assigned to the selected tab is quite simple. When a tab is selected, all controls who's Left+Width is >= 0, but not assigned to that tab are simply moved off the visible area of the control! The amount they are moved seems to always be the same - 5000 pixels to the left. Similarly, any control who's Left+Width is less than 0, but assigned to the selected tab, are moved 5000 pixels to the right. It seems that each tab has a corresponding Boolean for every control. What this means, is that you can easily "bring back" any control from any tab so that it shows on the selected tab. Moreover, the control can be assigned to multiple tabs!

    Here is a simple technique that makes a control (in this case a textbox) show on every tab.
    Code:
    Private Sub SSTab1_Click(PreviousTab As Integer)
    If Text1.Left < 0 Then Text1.Left = Text1.Left + 5000 * Screen.TwipsPerPixelX
    End Sub
    You can also observe the behavior of the control at design-time. Just place a control onto the SSTab, then select another tab. Now use the dropdown box on the Properties Window to select the hidden control. You will note that the Left property has become negative!

    Basically, each control is moved either to the left or right if a change in visibility is supposed to occure. Controls are assigned to a tab if the Left+Width is equal to or greater than zero, and unassigned if this value is less than zero. Since the controls are moved by 5000 pixels, this is the value you need to use in order for a control to become visible at the same location each time.

    An important thing to note, is that placing a control off to the right such that it is no longer visible does NOT unassign it from a tab.

    Placing a control into the SSTab at runtime essentially works the same as in the IDE.
    Oh...and if you don't like the look of the SSTab control, try the Style property

    Hmmm...should this be an article?
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726
    Hmmm...should this be an article?
    For sure.
    I suggest you a title for it: "Under the hood of SStab"
    (if for some reason you could not use the "SSTab Exposed, demystified, and beaten with a stick", which is nice!)


    Really Nice, WizzBang!
    Last edited by Cimperiali; July 21st, 2004 at 08:11 AM.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Jan 2002
    Location
    Quebec/Canada
    Posts
    124
    This is very interesting Wiz,

    I noticed the behavior before using a new control. I first though that control was buggy when I moved it around. Then after investigation I found that it was sstab fault but I never knew why it did this. I think your post is interesting and complete, it should make a good article.

    Heulsay

  4. #4
    Join Date
    Sep 2001
    Location
    Québec, Canada
    Posts
    1,923

    Thumbs up

    Quite interesting, if you make an article, you could try analysing other tabbed control (Multipage, TabStrip, Forms 2.0 TabStrip) and see if they use the same technic.

    JeffB
    CodeGuru VB FAQ Visual Basic Frequently Asked Questions
    VB Code color Tool to color your VB code on CodeGuru
    Before you post Importants informations to know before posting

  5. #5
    Join Date
    Oct 2003
    Location
    Timisoara, Romania
    Posts
    460
    Very nice finding that out, I almost hit my head on the walls with that SSTab I can't belive it is so simple after reading your post. I rated it excelent
    You liked it? Please show your gratitude and rate it!

    There is no 'patch' for stupidity.

  6. #6
    Join Date
    Sep 2002
    Location
    England
    Posts
    530

    Re: SSTab Exposed, demystified, and beaten with a stick

    Evening all,

    I had a look at this thread a little while ago and wondered why I couldn't remember encountering sizing/positioning problems with controls on the ssTab before, even though I have used them extensively in the past. Even recomended this thread to VMA for whom it worked a treat, but still I couldn't remember having any probs with it myself!!

    Now, for the first time in 18 months I am using this control again and it hit me straight away why I didn't recall such a problem & solution - I never needed to!

    Not saying the following is a better solution, just an alternative. Check it out:

    Code:
    Private Sub SizeControls()
    	
        'call this sub from your sstab_click or form_resize (though form_resize not much use in this example!) and bingo!
        
        Select Case SSTab1.Tab
        
            Case 0
                Text1.Left = 1000
            Case 1
                Text2.Left = 2000
            Case 2
                Text3.Left = 3000
            Case 3
                Text4.Left = 4000
            Case 4
                Text5.Left = 5000
    
        End Select
        
    End Sub
    
    Private Sub SSTab1_Click(PreviousTab As Integer)
    
        SizeControls
    
    End Sub
    Top explanation on how it works though, Wizbang!

    Cheers

  7. #7
    Join Date
    Jul 2006
    Posts
    2

    Re: SSTab Exposed, demystified, and beaten with a stick

    Hello forum, this mi first mesage here..

    Very, very interesting, I never suspect this. In any time, I see what any control are in other tab, and always I thinked what I wrong in put it.

    This es very use. for example seeng jvbd02 tell it... may deducting, build one owner tab same but better controlled.

    Now go to experiment if tabsPerRow affect too in top or no. Comprove, don't affect to top-botton, only left-right.

    Attached Images Attached Images  

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

Featured