Click here to Skip to main content
16,009,156 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
HI

i try for change header color of tab pages in tab controls with this code

VB
Dim g As Graphics = TabControl1.CreateGraphics

   Dim rect As Rectangle = New Rectangle(((TabControl1.SelectedIndex * TabControl1.ItemSize.Width) _
                   + 2), 2, (TabControl1.ItemSize.Width - 2), (TabControl1.ItemSize.Height - 2))
   g.FillRectangle(Brushes.Lime, rect)
   g.DrawString(TabControl1.SelectedTab.Text, New Font(TabControl1.SelectedTab.Font, FontStyle.Bold), Brushes.Red, rect)</pre>


this code

change header color of selected tab page

how to use this code or new way for change color of tabpage 3 JUST???</pre>
Posted

#
private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
{
    // This event is called once for each tab button in your tab control

    // First paint the background with a color based on the current tab

   // e.Index is the index of the tab in the TabPages collection.
    switch (e.Index )
    {
        case 0:
            e.Graphics.FillRectangle(new SolidBrush(Color.Red), e.Bounds);
            break;
        case 1:
            e.Graphics.FillRectangle(new SolidBrush(Color.Blue), e.Bounds);
            break;
        default:
            break;
    }

    // Then draw the current tab button text
    Rectangle paddedBounds=e.Bounds;
    paddedBounds.Inflate(-2,-2);
    e.Graphics.DrawString(tabControl1.TabPages[e.Index].Text, this.Font, SystemBrushes.HighlightText, paddedBounds);

}

Setting the DrawMode to 'OwnerDrawnFixed' means each tab button has to be the same size (ie Fixed).

However if you want to change the size of all tab buttons, you can set the tab control's SizeMode property to 'Fixed' and then change the ItemSize property.

Thanks & Regard
Sham :)
 
Share this answer
 
Thank u for ur answer

but i want to change header color of tabpage 3 with click button! not default!
 
Share this answer
 
Comments
ridoy 8-Sep-13 13:06pm    
you need to remove this comment,this is not an answer.Use Have a Question or Comment? button to do a comment.
 
Share this answer
 
friends i want to wink tab page

on open new tab in tab control tab pages, new tab page start wink

like this picture


http://s3.picofile.com/file/7928296020/tab_wink.jpg[^]


login tab page not selected but wink and change header color


Ex me i cant speak english very good

can u understand me???

please help!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900