Results 1 to 3 of 3

Thread: Tab Text Properties

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2003
    Location
    Chicagoland
    Posts
    92

    Tab Text Properties

    This seems like a simple question, but I've been racking my brains trying to figure out how to do it.

    As some of you may know from helping me before, my program adds tabpages to a tabcontrol at runtime. Certain tabpages are more important than others and my users were wondering if I could implement some kind of color-coding scheme for the text on the tab. For instance, a tab with the text "1MGH" would be red. "2TRG" and "2TCG" would be green, etc.

    I can't figure out how to do this at design time, much less runtime.

    I have been able to make them all bold by setting the tabcontrol font property at designtime, but if I try to play with it at runtime, it says it is a read only property.

    Any ideas?

  2. #2
    Addicted Member Hole-In-One's Avatar
    Join Date
    Mar 2003
    Location
    Minnesota
    Posts
    195
    Try This:

    Code:
    Private tabTextArea As RectangleF
    
        
        Public Sub Newpage()
            Dim tabControl1 As New TabControl()
            Dim tabPage1 As New TabPage()
    
            ' Allows access to the DrawItem event. 
            tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed
    
            tabControl1.SizeMode = TabSizeMode.Fixed
            tabControl1.Controls.Add(tabPage1)
            tabControl1.ItemSize = New Size(80, 30)
            tabControl1.Location = New Point(25, 25)
            tabControl1.Size = New Size(250, 250)
            tabPage1.TabIndex = 0
            ClientSize = New Size(300, 300)
            Controls.Add(tabControl1)
    
            tabArea = tabControl1.GetTabRect(0)
            tabTextArea = RectangleF.op_Implicit(tabControl1.GetTabRect(0))
    
            ' Binds the event handler DrawOnTab to the DrawItem event 
            ' through the DrawItemEventHandler delegate.
            AddHandler tabControl1.DrawItem, AddressOf DrawOnTab
        End Sub
    
        ' Declares the event handler DrawOnTab which is a method that
        ' draws a string on the tabPage1 tab.
        
    Private Sub DrawOnTab(ByVal sender As Object, ByVal e As DrawItemEventArgs)
            Dim g As Graphics = e.Graphics
            Dim p As New Pen(Color.Blue)
            Dim font As New Font("Arial", 10.0F)
            Dim brush As New SolidBrush(Color.Red)
    
            g.DrawString("tabPage1", font, brush, tabTextArea)
        End Sub
    
    'Add the new tab page 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Newpage()
    
        End Sub
    Got it out of the help files in VS.net

    Its a starting point
    Last edited by Hole-In-One; Dec 1st, 2003 at 01:24 PM.

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    To change a font you have to create a new font object and base it on the old one here is an example:
    VB Code:
    1. 'make the current font bold
    2. Me.Font = New Font(Me.Font, FontStyle.Bold)

    Also there is no default way to change the color of the actual tab unless you do as Hole-In-One suggests and ownerdraw it. BUT the tabs have support to show icons on them. You can have different icons for the different important tabs. Just create an ImageList on the form with all the icons then assign it to the tabcontrols and at runtime set the ImageIndex property to the index of the image based on the text of the tab.

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