Announcement

Collapse
No announcement yet.

Tabcontrol captions in bold

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Tabcontrol captions in bold

    hi,

    How can I make the selected Tab's caption to be bold where all
    the other remain normal. I looked in the MSDN but I can't find
    any style that would do this. Does anyone see the light ?

    Thanks

    Steve.

    ------------------
    So here we are, this is the end.
    But all that dies, is born again.
    - From The Ashes (In This Moment)

  • #2
    That is not a standard behavior for a tab-control, so you'll probably have to use an ownerdraw tab-control - a fair amount of work just to draw one tab in bold.

    On an aside, Jules Marchildon once created a vertical tab control using an ownerdraw listbox (very creative!). This may be in the source code forum. IIRC, it was somewhere around March 2000.

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      Steven;

      Something from SGT Peppers Lonely Hearts Club Band...

      HTH
      Regards,
      Jules

      Code:
      '-----------------------------------------------------------------------------
      ' Bold selected Tab
      ' Code based from Peter Lameijn, disabled tab example from this forum.
      '
      '-----------------------------------------------------------------------------
      #Compile Exe
      #Include "win32api.inc"
      #Include "commctrl.inc"
       
      %MAXTABS = 8
      %IDC_TAB = 101
      %IDC_LBL = 102
       
      Global hDlg As Long, lTCI As TC_ITEM, lZStr As Asciiz * 64, hTab() As Long, lRect As RECT, TabId() As String
       
      '----------------------------------------------------------------------------
      '
      '
      '----------------------------------------------------------------------------
      CallBack Function CbMain ()
       
        Local lPnmh As NMHDR Ptr, lRet As Long, lDBU As Long, lTCI As TC_ITEM, lDISPtr As DRAWITEMSTRUCT Ptr
        Static PrevSel As Long
        Local hFont As Long
         
        Select Case CbMsg
       
          Case %WM_DRAWITEM
       
            lDisPtr = CbLparam
            lZStr = TabID$( @lDisPtr.ItemId+1 )
       
            Call TabCtrl_GetItemRect( hTab(0), @lDisPtr.ItemId, lRect )
          
            IF @lDisPtr.ItemState = %ODS_SELECTED THEN
                  LOCAL rc AS RECT : rc = lRect : rc.nBottom = rc.nBottom + 4
                  Call FillRect( @lDisPtr.hDC,rc,GetStockObject(%LTGRAY_BRUSH) )
                  '*Use a bold font if selected
                  hFont = CreateFont(-8,0,0,0,%FW_BOLD,0,0,0,0,0,0,0,0,"MS Sans Serif")
            ELSE
                  '*Or a normal one if not selected
                  hFont = CreateFont(-8,0,0,0,%FW_NORMAL,0,0,0,0,0,0,0,0,"MS Sans Serif")
            END IF
             
             hFont = SelectObject(@lDisPtr.hDC,hFont)
             Call SetTextColor( @lDisPtr.hDc, Rgb(@lDisPtr.ItemId*35,0,[email protected]*35) )
             Call TextOut( @lDisptr.hDc, lRect.nLeft + 5, lRect.nTop + 3, lZStr, Len (lZStr) )
             Call DeleteObject(SelectObject(@lDisPtr.hDC,hFont))
              
          Case %WM_NOTIFY
            lPnMh = CbLparam
            Select Case @lPnMh.Code
              Case %TCN_SELCHANGE
                lRet = TabCtrl_GetCursel (hTab(0))
                  Call ShowWindow( hTab(PrevSel+1), %SW_HIDE )
                  Call ShowWindow( hTab(lRet+1), %SW_SHOW )
                  PrevSel = lRet
            End Select
        End Select
      End Function
       
      '-----------------------------------------------------------------------------
      '
      '
      '-----------------------------------------------------------------------------
      Function PbMain() As Long
       
        Dim hTab(10), TabID(10), lCnt As Long
       
        Call InitCommonControls()
       
        Dialog New 0, "Test Tab",,,300,200, %WS_VISIBLE Or %WS_SYSMENU To hDlg
        Control Add "SysTabControl32",  hDlg, %IDC_TAB, "",5,5,290,160,%WS_CHILD Or %WS_VISIBLE Or _
                                              %TCS_MULTILINE Or %TCS_RIGHTJUSTIFY Or %TCS_OWNERDRAWFIXED OR %TCS_TABS
                                               
        Control Handle hDlg, %IDC_TAB To hTab(0)
       
        For lCnt = 1 To %MAXTABS
          TabID$(lCnt) = "Tab #" + Trim$(Str$(lCnt))
          Dialog New hTab(0), TabID$(lCnt),10,10,280,160, %WS_VISIBLE Or %WS_CHILD To hTab(lCnt)
          Control Add Label, hTab(lCnt), -1, "This is "+TabId$(lCnt),5,5,100,15
          lZStr        = TabID$(lCnt)
          lTCI.mask    = %TCIF_TEXT
          lTCI.pszText = VarPtr (lzStr)
          Call TabCtrl_InsertItem( hTab(0), lCnt -1, lTCI )
          Call GetClientRect( hTab(0), lRect )
          Call InflateRect( lRect, -10 , -56 )
          Call OffsetRect(  lRect, -4 , -5 )
          Call MoveWindow( hTab(lCnt),lRect.nLeft,lRect.nTop,lRect.nRight,lRect.nBottom, %True )
        Next
       
        Call ShowWindow( hTab(1), %SW_SHOW )
        Dialog Show Modal hDlg, Call CbMain
       
      End Function
      Best regards
      Jules
      www.rpmarchildon.com

      Comment


      • #4
        You're the man Jules !! Thanks a lot !!





        ------------------
        So here we are, this is the end.
        But all that dies, is born again.
        - From The Ashes (In This Moment)

        Comment


        • #5
          Steven;

          You are very welcome!

          Regards,
          Jules
          Best regards
          Jules
          www.rpmarchildon.com

          Comment

          Working...
          X