Results 1 to 9 of 9

Thread: [RESOLVED] Different Tab Widths on SSTab Control

  1. #1

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Resolved [RESOLVED] Different Tab Widths on SSTab Control

    Hi All,

    This one will probably be filed under the impossible (or too difficult to mess with) category. However, it's crossed my minds many times through the years, and it has come up again today. As many know, I make extensive use of the SSTab control (TabCtl32.ocx, "Microsoft Tabbed Dialog Control 6.0 (SP6)").

    Under most cases, I make sure that all the tabs fit on one row. Or, said differently, the number of tabs is fixed at design-time, with that number being the same as the TabsPerRow. In this situation, there are times when it would be quite useful to have the last two-or-three tabs more narrow than the others. In other words, it's "Misc1", "Misc2", etc, information that's less important. If those could be more narrow, that would be a wonderful thing for me.

    Okay, some things I already know about:
    1) Sure, I could switch over to some other control (or maybe roll my own) and get it done. But I'm just not going to do that unless I have more motivation than I currently have.
    2) Sure, I could put a nested SSTab on my "Misc" tab. That's probably the route that I'll go, but it'd still be nice to not have to do that.

    I think I'm probably one of the forum experts on this SSTab control. So, if I don't have this answer, I doubt that someone else will. But I thought I'd ask anyway. I'm sometimes surprised at what I learn from my participation on these forums.

    Y'all Take Care,
    Elroy
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Different Tab Widths on SSTab Control

    I know you don't want to rework everything, but the TabStrip (COMCTL32.OCX) both accepts CC6 styles for a look compatible with Windows and has "tabs" that vary in width based on caption values.

  3. #3
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,997

    Re: Different Tab Widths on SSTab Control

    Quote Originally Posted by Elroy View Post
    So, if I don't have this answer, I doubt that someone else will. But I thought I'd ask anyway.
    Don't doubt. (LOL)

    I'm working in a SStab direct replacement but with enhanced features (being themed is one), I'll post it in the forum when it's done.
    I estimate it will be finished in a couple of weeks.

    But aside from that, for your specific problem, did you try setting the Style property to ssPropertyPage?

  4. #4

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: Different Tab Widths on SSTab Control

    @Eduardu: Well by golly, you just absolutely nailed it. You gotta love these forums. I've just never once played around with the style property of the SSTab control. But, maybe with some extra spaces in some of my captions, that's going to do precisely what I want.

    I knew there was a reason I posted the question out here.

    Also, Eduardo, if it were me, I'd start with Krool's controls to write a replacement for the SSTab control. He's already got many of the related issues already worked out. I've actually thought about doing it as well, but other projects always intervene.

    Again, BIG thanks.
    Elroy

    EDIT1: Also, there are a couple of bugs in the SSTab control, nothing serious but still a touch annoying. One is TabStops in containers which are on the SSTab control. They don't get handled correctly. Another has to do with the carat and the way comboboxes auto-close their pulldown (or not, when switching tabs). I've got a class module that fixes both of them. I've posted it before, but I'll post it again if you like.
    Last edited by Elroy; Oct 4th, 2017 at 03:00 PM.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  5. #5
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,997

    Re: Different Tab Widths on SSTab Control

    Quote Originally Posted by Elroy View Post
    I'd start with Krool's controls to write a replacement for the SSTab control.
    That was what I also thought, but when I went to check the code of Krool's TabStrip I found he intantiates a Windows Common Control TabStrip. I mean, it is not "owner drawn". It could have been used if the control was limited to the Style PropertyPage, but I also wanted the "standard" SSTab Style which is TabbedDialog.

    Quote Originally Posted by Elroy View Post
    Another has to do with the carat and the way comboboxes auto-close their pulldown (or not, when switching tabs). I've got a class module that fixes both of them. I've posted it before, but I'll post it again if you like.
    Yes, please, I'm not aware of that bug.

  6. #6

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: Different Tab Widths on SSTab Control

    Hi Eduardo,

    The following is code I have in a class named "cls_Gen_FixTabCtl". And then following is usage within a form containing a SSTab control.


    Code:
    
    Option Explicit
    '
    Dim WithEvents tabCtl As SSTab
    Dim frm As Form
    Dim TabStops() As Boolean
    '
    ' A primary purpose of this fix is to correctly control the tab stops.
    ' To make the appearance of tabs, the SSTab control simply moves the controls out of view.
    ' An artifact of this approach is that the controls are still able to get the focus when the
    ' user uses the TAB key.  The following code corrects this problem by appropriately turning
    ' on and off the TabStop properties of the controls as the user tabs from one tab to another.
    '
    ' Another problem has to do with ComboBoxes.  When changing to a new tab, dropdown comboboxes
    ' will have their text selected.  The combobox will not have the focus, but their text will be
    ' selected.  The primary problem with this is that it right-justifies the text when there is more
    ' text than will fit in the textbox portion of the combobox, and this is confusing to users.
    ' This problem is corrected in the following code.
    '
    
    Friend Sub SetTabControl(TheTabControl As SSTab, TheForm As Form)
        ' Call this in the form load event.
        Dim ctl As Control
        Dim Ptr As Long
        '
        Set tabCtl = TheTabControl
        Set frm = TheForm
        '
        ' Store the true value of the TabStops.
        ReDim TabStops(0 To frm.Controls.Count - 1)
        ' Not all controls have TabStop property, so we must set error trapping.
        On Error Resume Next
            For Ptr = 0 To frm.Controls.Count - 1
                TabStops(Ptr) = frm.Controls(Ptr).TabStop
            Next Ptr
        On Error GoTo 0
    End Sub
    
    Friend Sub SetTabStopsAccordingly()
        ' Call this in the form activate event.
        ' After this first call, it will automatically be called when the tabs change.
        Dim ctl As Control
        Dim ctlTheControlOrContainer As Control
        Dim ItsOnTheTabControl As Boolean
        Dim Ptr As Long
        '
        For Ptr = 0 To frm.Controls.Count - 1
            Set ctl = frm.Controls(Ptr)
            Set ctlTheControlOrContainer = ctl ' The control might be on a container that's on the SSTab, rather than directly on the SSTab.
            Do
                Select Case True
                Case TypeOf ctlTheControlOrContainer.Container Is SSTab
                    ItsOnTheTabControl = True
                    Exit Do ' The way out.
                Case TypeOf ctlTheControlOrContainer.Container Is Form
                    ItsOnTheTabControl = False
                    Exit Do ' The way out.
                End Select
                Set ctlTheControlOrContainer = ctlTheControlOrContainer.Container ' Must deal with controls nested deeper than the SSTab control.
            Loop
            If ItsOnTheTabControl Then
                ' Not all controls have TabStop property, so we must set error trapping.
                On Error Resume Next
                    If ctlTheControlOrContainer.Left >= 0 Then
                        ctl.TabStop = TabStops(Ptr) ' If it's showing, restore the original TabStop value.
                        ' Must also fix the problem with combo boxes having an internal focus set.
                        ctl.SelStart = 0
                        ctl.SelLength = 0
                    Else
                        ctl.TabStop = False
                    End If
                On Error GoTo 0
            End If
        Next Ptr
    End Sub
    
    Private Sub tabCtl_Click(PreviousTab As Integer)
        SetTabStopsAccordingly
    End Sub
    
    Private Sub tabCtl_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
        ' This allows other controls to close up when user click off.
        ' The problem is that clicking into the body of the tab control does NOT cause change in focus.
        ' The control with the focus keeps it, and it may not close up as typically happens when clicking on dead space of a form.
        ' You may also want to consider placing this "SetFocus" code on the labels on the tabs.  This is NOT automatically done
        ' because the programmer may want to use a label click for other purposes.
        tabCtl.SetFocus
    End Sub
    
    

    Now, assuming we have an SSTab control named "tabExamData", we'd fix those bugs as follows:

    Code:
    
    Option Explicit
    '
    Dim FixTabControl As New cls_Gen_FixTabCtl
    '
    
    
    Private Sub Form_Load()
        tabExamData.Tab = 0
        FixTabControl.SetTabControl tabExamData, Me
    
    
    
    
    End Sub
    
    Private Sub Form_Activate()
        FixTabControl.SetTabStopsAccordingly
    
    
    
    
    End Sub
    
    
    Notice that both the Form_Load and Form_Activate pieces are needed.

    Enjoy,
    Elroy
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  7. #7
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: [RESOLVED] Different Tab Widths on SSTab Control

    Elroy

    You marked this as RESOLVED, but what the heck ...

    1. Default .. .Style = ssStyleTabbedDialog

    Name:  sstabStyle1.png
Views: 723
Size:  3.2 KB

    2. Change .. .Style = ssStylePropertyPage

    Code:
    Sub Command2_click()
        '
        With SSTab1
            ' change Tab Style
            If .Style = ssStylePropertyPage Then
                .Style = ssStyleTabbedDialog
                .TabMaxWidth = 0
                .TabHeight = 600    ' 295
            ElseIf .Style = ssStyleTabbedDialog Then
                .Style = ssStylePropertyPage
                .TabMaxWidth = 0
                .TabHeight = 295
            End If
        End With
        '
    End Sub
    Name:  sstabStyle2.png
Views: 605
Size:  2.9 KB

    3. Revert to default, but change .TabHeight

    Name:  sstabStyle3.png
Views: 606
Size:  3.6 KB

    I'm not sure that I like the visual effects of approach #2 .. boo

    Spoo

  8. #8

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: [RESOLVED] Different Tab Widths on SSTab Control

    Ahhh, well Spoo, I'm barely here until I get home next week. And I haven't really played around with the solution. But the bit that I tested looked good. I'll mess with it more next week.

    Also, a thread being marked "resolved" seldom seems to slow people down when they have more to say.

    You Take Care,
    Elroy
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  9. #9
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,997

    Re: Different Tab Widths on SSTab Control

    Quote Originally Posted by Eduardo- View Post
    Don't doubt. (LOL)

    I'm working in a SStab direct replacement but with enhanced features (being themed is one), I'll post it in the forum when it's done.
    I estimate it will be finished in a couple of weeks.
    It took a little longer.
    I released it today for beta testing here.

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