Click here to Skip to main content
6,291,124 members and growing! (15,238 online)
Email Password   helpLost your password?
Desktop Development » Tabs & Property Pages » Tabs and Property Pages     Intermediate License: The Code Project Open License (CPOL)

Coloring Tab Control

By sreejith ss nair

Coloring Tab Control
C#, Windows, .NET 1.0, .NET 1.1VS.NET2003, Dev
Posted:14 Sep 2004
Views:111,234
Bookmarked:31 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
50 votes for this article.
Popularity: 6.12 Rating: 3.60 out of 5
7 votes, 14.0%
1
3 votes, 6.0%
2
5 votes, 10.0%
3
17 votes, 34.0%
4
18 votes, 36.0%
5

Introduction

Tabcontrol is not at all unknown to windows developers. Microsoft included this control from Visual Studio to Visual Studio.NET SDK to enhance developers productivity and end users better experience. I agree that our windows development must flow some standard to give better user experience. Here I am trying to give little more enhancement on control appearance if and only if developer want to do it.

Background

This article is small in size and can apply in your different application only if it must be a winform development. You can refer this article to update your tab control's appearances in your parent window.

By default or through any properties the existing VS.NET SDK won't support features which will enhance the appearances of tab pages like changing font appearances , color,caption back color etc. Here what I am trying to do is , override a little and got into solution. So you can use this idea to enhance your product or project.

If you feel this is good then don't forget to vote and give put your valuable suggestions.

If you check the property list of tabcontrol. You will came to to about DrawMode property. DrawMode property decides that how tabpages are drawn in your application. If you check the values then you will came to that there is two values are there which is assignable for the property DrawMode.

DrawMode Enumeration

Normal

This enumerated value will specify that operating system will decide to draw on behalf of developers.

OwnerDrawn

This enumerated value will specify that developer is responsible for drawing the appearance of tab page.

Suppose if you want to draw by yourself then you need to define event handler for TabControl's DrawItem Event.

Here also I am doing the same thing. Suppose it you want to change the appearance of tabpage of any tabcontrol then you need to set

  1. DrawMode property to OwnerDrawFixed.
  2. Override the DrawItem event handler definition.

Source Code

private void tabControl1_DrawItem(object sender, 
  System.Windows.Forms.DrawItemEventArgs e)
   {
       try
        {
          //This line of code will help you to 

          //change the apperance like size,name,style.

          Font f;
          //For background color

          Brush backBrush;
          //For forground color

          Brush foreBrush;
          //This construct will hell you to decide 

          //which tab page have current focus

          //to change the style.

          if(e.Index == this.tabControl1.SelectedIndex)
          {
          //This line of code will help you to 

          //change the apperance like size,name,style.

          f = new Font(e.Font, FontStyle.Bold | FontStyle.Bold);
          f = new Font(e.Font,FontStyle.Bold);
          backBrush = new System.Drawing.SolidBrush(Color.DarkGray);
          foreBrush = Brushes.White;
        }
        else
        {
          f = e.Font;
          backBrush = new SolidBrush(e.BackColor); 
          foreBrush = new SolidBrush(e.ForeColor);
        }
          //To set the alignment of the caption.

          string tabName = this.tabControl1.TabPages[e.Index].Text;
          StringFormat sf = new StringFormat();
          sf.Alignment = StringAlignment.Center;
          //Thsi will help you to fill the interior portion of

          //selected tabpage.

//Continue.........

  }
}

Note

Full source code with an example is given with this article.

License

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

About the Author

sreejith ss nair


Member
Sreejith S S Nair is a promising architect and has been programming since 2001. He is a certified professional in both MCPD and MCTS. He is a mathematics graduate with masters in computer science and international business.

He was born and bred in India and happen to spend some time in Europe. He loves to spend leisure with family & friends.

You can reach him at sreejithssnair@hotmail.com
Occupation: Architect
Company: Freelance
Location: India India

Other popular Tabs & Property Pages articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 27 (Total in Forum: 27) (Refresh)FirstPrevNext
GeneralThanks for the article PinmemberDeadlyB6:26 12 May '09  
GeneralProblem When RightToLeftLayout [modified] PinmemberAeyd M.0:14 25 Sep '07  
GeneralRe: Problem When RightToLeftLayout Pinmembersreejith ss nair18:53 25 Sep '07  
GeneralRe: Problem When RightToLeftLayout Pinmembersreejith ss nair19:19 7 Oct '07  
GeneralArticle Extension Pinmemberag1h6:44 3 Feb '07  
GeneralRe: Article Extension Pinmembersreejith ss nair18:50 25 Sep '07  
GeneralRe: Article Extension Pinmembersreejith ss nair19:19 7 Oct '07  
GeneralBackcolor property PinmemberMBrooker9:20 26 Oct '06  
GeneralRe: Backcolor property Pinmembersreejith ss nair18:51 25 Sep '07  
GeneralRe: Backcolor property Pinmembersreejith ss nair19:20 7 Oct '07  
Generalredrawing giving awfull look to application Pinmemberkhaadem4:11 24 Jan '06  
GeneralRe: redrawing giving awfull look to application Pinmembersreejith ss nair4:24 24 Jan '06  
GeneralRe: redrawing giving awfull look to application Pinmemberkhaadem4:49 24 Jan '06  
GeneralRe: redrawing giving awfull look to application Pinmembersreejith ss nair23:10 30 Jan '06  
GeneralRe: redrawing giving awfull look to application Pinmembersreejith ss nair19:20 7 Oct '07  
GeneralHow about the rest of the tab control PinmemberJohn08:07 11 Dec '04  
GeneralRe: How about the rest of the tab control PinmemberBalder1978-212:53 5 Sep '05  
GeneralRe: How about the rest of the tab control Pinmemberrohinivn20:33 19 Mar '07  
GeneralRe: How about the rest of the tab control Pinmemberrohinivn23:20 19 Mar '07  
GeneralRe: How about the rest of the tab control Pinmembersreejith ss nair19:23 7 Oct '07  
GeneralRe: How about the rest of the tab control Pinmembersreejith ss nair19:20 7 Oct '07  
GeneralDerived TabPage PinmemberGuggsdu3:51 28 Oct '04  
GeneralRe: Derived TabPage PinmemberStumpy84217:40 20 Dec '05  
GeneralRe: Derived TabPage Pinmembersreejith ss nair19:23 7 Oct '07  
GeneralDear, PinmemberPradeep K V19:15 21 Sep '04  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 14 Sep 2004
Editor: Nishant Sivakumar
Copyright 2004 by sreejith ss nair
Everything else Copyright © CodeProject, 1999-2009
Web16 | Advertise on the Code Project