Geeks With Blogs
Gaurav Taneja Great dreams... never even get out of the box. It takes an uncommon amount of guts to put your dreams on the line, to hold them up and say, "How good or how bad am I?" That's where courage comes in.
To change the color of Tab control
Add this event handler
  1. DrawMode property to OwnerDrawFixed.
  2. Override the DrawItem event handler definition.
tabControl2.DrawItem += new DrawItemEventHandler(OnDrawItem);
step 2
private void OnDrawItem(object sender, DrawItemEventArgs e)
            TabPage CurrentTab = tabControl2.TabPages[e.Index];
            Rectangle ItemRect = tabControl2.GetTabRect(e.Index);
            SolidBrush FillBrush = new SolidBrush(Color.Red);
            SolidBrush TextBrush = new SolidBrush(Color.White);
            StringFormat sf = new StringFormat();
            sf.Alignment = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;
            //If we are currently painting the Selected TabItem we'll
            //change the brush colors and inflate the rectangle.
            if (System.Convert.ToBoolean(e.State & DrawItemState.Selected))
                FillBrush.Color = Color.PaleTurquoise;
                TextBrush.Color = Color.Red;
                ItemRect.Inflate(2, 2);
            //Set up rotation for left and right aligned tabs
            if (tabControl2.Alignment == TabAlignment.Left || tabControl2.Alignment == TabAlignment.Right)
                float RotateAngle = 90;
                if (tabControl2.Alignment == TabAlignment.Left)
                    RotateAngle = 270;
                PointF cp = new PointF(ItemRect.Left + (ItemRect.Width / 2), ItemRect.Top + (ItemRect.Height / 2));
                e.Graphics.TranslateTransform(cp.X, cp.Y);
                ItemRect = new Rectangle(-(ItemRect.Height / 2), -(ItemRect.Width / 2), ItemRect.Height, ItemRect.Width);
            //Next we'll paint the TabItem with our Fill Brush
            e.Graphics.FillRectangle(FillBrush, ItemRect);
            //Now draw the text.
            e.Graphics.DrawString(CurrentTab.Text, e.Font, TextBrush, (RectangleF)ItemRect, sf);
            //Reset any Graphics rotation
            //Finally, we should Dispose of our brushes.
Posted on Wednesday, December 10, 2008 11:34 PM Window Application | Back to top

Comments on this post: To change the colour of TAB control

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Gaurav Taneja | Powered by: