-
Oct 4th, 2017, 09:56 AM
#1
[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.
-
Oct 4th, 2017, 12:34 PM
#2
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.
-
Oct 4th, 2017, 01:35 PM
#3
Re: Different Tab Widths on SSTab Control
Originally Posted by Elroy
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?
-
Oct 4th, 2017, 02:57 PM
#4
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.
-
Oct 4th, 2017, 09:51 PM
#5
Re: Different Tab Widths on SSTab Control
Originally Posted by Elroy
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.
Originally Posted by Elroy
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.
-
Oct 5th, 2017, 06:00 AM
#6
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.
-
Oct 6th, 2017, 07:01 AM
#7
Re: [RESOLVED] Different Tab Widths on SSTab Control
-
Oct 6th, 2017, 07:40 AM
#8
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.
-
Nov 22nd, 2017, 08:42 AM
#9
Re: Different Tab Widths on SSTab Control
Originally Posted by Eduardo-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|