Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

multi-tabbed form-how to highlight active tab? 1

Status
Not open for further replies.

KH2009

IS-IT--Management
Jan 30, 2009
8
US
I have a form with nine tabs. I'd like to be able to bolden or highlight the tab that the user is currently working in. I can't find any info on how this might be accomplished. Does anyone have a suggestion? I'm not a code person but if pushed would be willing to give it a whirl.

Thanks!
Kathy
 
There is not a native way to do this. There are some advanced API code that does this. However there is an easier way to do this. You can build a tab control and set the format property to "tabs, buttons, or none". If you pick "none" you get a tab control with no tabs. You can then put labels on top of the control and make them look like tabs. With a little work you can make the labels change colors and make the tab change colors. You can also change the format property of the selected label (sink or raise) to make it look selected. Hint to change the tab control page, change the value of the tab control

to go to page 2 (0 indexed)
me.someTabCntrl.value = 1
 
Thank you for the advice, MajP. Sounds like I might be able to juryrig this after all. :)
 
How are ya KH2009 . . .

If you setup your tabs this way, instead of default colors you simply hilite the proper box with the color of your choice ...

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
AceMan,
I think that looks like a lot of work and not a lot of utility. I think using a regular tab control with style of "none" is far easier and more flexible. You get the whole functionality of a tab control. Most times I use a tab there are multiple subforms. If you want colors on the tabs then simply put a colored rectangle on the tab.

I make it easy on my self and put rectangles on the tabs but set their color to the corresponding label color. That allows me to change the colors of my labels without spending formatting time on the boxes.

Here is the code with some exagerated hiliting of the selected tab.

Code:
Public Function changeTab(intTab As Integer)
    Me.tbCtrl1.Value = intTab - 1
    depressLabel (intTab)
End Function

Private Sub Form_Load()
  Dim lblCount As Integer
  Dim i As Integer
  lblCount = Me.tbCtrl1.Pages.Count
 'need to ensure you have as many labels as pages
 'need to ensure you labels are lbl1 to lblN
 'need to ensure your boxes are bx1 to bxN
  For i = 1 To lblCount
    Me.Controls("bx" & i).BackColor = Me.Controls("lbl" & i).BackColor
  Next i
End Sub


Public Sub depressLabel(intLabel As Integer)
  Dim lblCount As Integer
  Dim i As Integer
  lblCount = Me.tbCtrl1.Pages.Count
  For i = 1 To lblCount
    With Me.Controls("lbl" & i)
      'Raised and unBold
      .SpecialEffect = 1
      .FontBold = False
      .FontUnderline = False
      .FontItalic = 0
    End With
  Next i
  With Me.Controls("lbl" & intLabel)
    'Sunken Bold
    .SpecialEffect = 2
    .FontBold = True
    .FontUnderline = True
    .FontItalic = True
  End With
End Sub

Here is the demo

Showing a subform
awfix2.jpg
 
MajP . . . .

I'm not buffing your presentation ... I'm just presenting another option! From the way it looks (which I think is better and more fluid in color ... aka more pro!), its up to the op to decide. After all, the op seeks to only hilite the active tab! There's no law that saids it absolutely has to include all the functionality of a tab control!
TheAceMan1 said:
[blue]In all that we do, we only need things to do what we want![/blue]
What I presented is just a more fluid way ... as far as color is concerned. If the op doesn't want to do the work ... then I guess its your way that will reign forever!

[blue]Too many times we get ahead of ourselves in the power we believe we have to offer.[/blue] Until I ran across this method ... yours was the only one I used! Now all my clients have been updated to what I presented since 1990! Its all up to the op! [thumbsup2] There are no intrecacies!

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
AceMan,
You put in your post:
AceMan said:
Your Thoughts?
I assumed that meant both positive and negative feedback. I provided that I thought this approach more complicated and would be hard to manage (I still believe that). Your reply contained 9 exclamation points which seems a little strong. If you only want thoughts that agree with you why not sign it?
Your Thoughts?
(Please reply with only positive thoughts, in agreement with my proposed solution)
 
MajP . . .

[blue]I will not bicker with one of Tek-Tips finest! ...[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Ok here is a solution that maybe we both can agree on. It gives the pro-look, and is very easy to work with. Any thoughts, good or bad?

Requires the user to do only the following.
1) The user puts the following labels on the form:
lbl1,lbl2, to lblN where N is the number of pages. Provide each its own color.
lblHilite
lblStrip
user does not have to worry about sizing, positioning or formatting or adding event procedures. Code takes care of all of that.
2) The user adds tab control tbCntrl1

3) The user can keep the tab in "tab" style during design which allows quick and easy designing. Easy access to modifying controls on various tabs. Just like working with any tab control. My big issues was working with "pseudo tabs" stacked on each other. That seemed difficult to do any modification.

That is it. The code does the rest. Formats everything real nice and provides the functionality. The user can modify the depressLabel procedure to provide a different look. The code handles any number of tabs.


Code:
Public Function changeTab(intTab As Integer)
    Me.tbCtrl1.Value = intTab - 1
    depressLabel (intTab)
End Function
Private Sub Form_Load()
  Dim lblCount As Integer
  Dim i As Integer
  Dim lblWidth As Long
  Dim tempLeft As Long
  lblCount = Me.tbCtrl1.Pages.Count
 'need to ensure you have as many labels as pages
 'need to ensure your control labels are lbl1 to lblN
 'Need a lblHilite
  Me.tbCtrl1.Style = 2
  Me.tbCtrl1.BackStyle = 0
  'Format lblhilite
  
  With Me.lblHilite
    .Width = Me.tbCtrl1.Width
    .Height = Me.tbCtrl1.Height
    .Top = Me.tbCtrl1.Top
    .Left = Me.tbCtrl1.Left
    .Caption = ""
  End With
  lblWidth = lblHilite.Width / lblCount
  tempLeft = Me.lblHilite.Left
  For i = 1 To lblCount
    'Format labels
    With Me.Controls("lbl" & i)
      .Left = tempLeft
      .Width = lblWidth
      .Top = Me.tbCtrl1.Top - Me.lbl1.Height
      .Height = Me.lbl1.Height
      .OnClick = "=changeTab(" & i & ")"
    End With
    tempLeft = tempLeft + Me.Controls("lbl" & i).Width
  Next i
  'Format the strip between the labels and boxes
  With Me.lblStrip
     .Left = Me.lblHilite.Left
     .Top = Me.lbl1.Top + Me.lbl1.Height
     .Width = Me.lblHilite.Width
     .BackColor = Me.lbl1.BackColor
     .Caption = ""
   End With
End Sub
Public Sub depressLabel(intLabel As Integer)
  Dim lblCount As Integer
  Dim i As Integer
  lblCount = Me.tbCtrl1.Pages.Count
  For i = 1 To lblCount
    With Me.Controls("lbl" & i)
      'Flat and unBold
      .SpecialEffect = 0
      .FontBold = False
      .FontUnderline = False
      .FontItalic = 0
      .BorderStyle = 0
    End With
  Next i
  With Me.Controls("lbl" & intLabel)
    'Sunken Bold
    .SpecialEffect = 2
    .FontBold = True
    .FontUnderline = True
    .FontItalic = True
  End With
  Me.lblStrip.BackColor = Me.Controls("lbl" & intLabel).BackColor
  Me.lblHilite.BackColor = Me.Controls("lbl" & intLabel).BackColor
End Sub

What it looks like in design view
2z7eirb.jpg


What it looks like on open.

2nrfxy0.jpg


modified to select just one

xe3lg3.jpg
 
MajP . . .

[blue]Now thats [purple]poetry in motion![/purple][/blue] [thumbsup2]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top