July 21st, 2004, 07:58 AM
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.
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!
Private Sub SSTab1_Click(PreviousTab As Integer)
If Text1.Left < 0 Then Text1.Left = Text1.Left + 5000 * Screen.TwipsPerPixelX
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?
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!