Results 1 to 7 of 7

Thread: Tabs colour

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Resolved Tabs colour

    Is it possible to have the Tabs of a Tab Control with a picture or colour?
    Last edited by angelica; Sep 16th, 2008 at 04:58 AM.
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

  2. #2
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    Re: Tabs colour

    You can have tab pages with icons besides the tab text. Drop a ImageList control from Toolbox and then add images to it. Then set ImageList property of TabControl to this ImageList control that you dropped on form. Now set the ImageIndex property of each tab page which will display the icons from ImageList control of that ImageIndex.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: [RESOLVED] Tabs colour

    thanks Deepak,

    How come we can change the colour of the TabPage but not the button also? Anyway I can do that?
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

  4. #4

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: [RESOLVED] Tabs colour

    Hi Deepak,

    It's the Tab button I need to change to be like the Tab Page. Have a look at the pic. Is it possible to have the button where I have L/A, L/ABook etc in light green also?
    Last edited by angelica; Sep 16th, 2008 at 07:44 AM.
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

  6. #6
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    Re: Tabs colour

    Angelica,

    The Tab Control in .NET does not expose properties to change its back ground and foreground color. This can be achieved by overriding the DrawItem event of the control. Following are the steps involved to do the same.

    1. Set the TabControl's DrawMode to OwnerDraw
    2. Handle the DrawItem event to draw things yourself

    vb.net Code:
    1. Private Sub TabControl1_DrawItem( _
    2.     ByVal sender As Object, _
    3.     ByVal e As System.Windows.Forms.DrawItemEventArgs _
    4. ) Handles TabControl1.DrawItem
    5.  
    6.     Dim g As Graphics = e.Graphics
    7.     Dim tp As TabPage = TabControl1.TabPages(e.Index)
    8.     Dim br As Brush
    9.     Dim sf As New StringFormat
    10.     Dim r As New RectangleF(e.Bounds.X, e.Bounds.Y + 2, e.Bounds.Width, e.Bounds.Height - 2)
    11.  
    12.     sf.Alignment = StringAlignment.Center
    13.  
    14.     Dim strTitle As String = tp.Text
    15.  
    16.     br = New SolidBrush(tp.BackColor)
    17.     g.FillRectangle(br, e.Bounds)
    18.     br = New SolidBrush(tp.ForeColor)
    19.     g.DrawString(strTitle, TabControl1.Font, br, r, sf)
    20. End Sub

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: Tabs colour

    ok Deepak, many thanks
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

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