arif sharif

arif sharif

  • NA
  • 34
  • 0

how to change the back color of tab control in windows appplication

Apr 22 2007 11:51 PM

hi every one,
In Tab control i want to change the color of  the tab (rectangular) at the top when the align=left as well as i want how the rectangular tab look in default mode(when it is align=left) 
i found some code  and used it but it is not displaying the tab name at runtime .
the code which i used :

In load iam making Drawmode=owner drawfixed in tab properties

private void TabControl1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
 Graphics g = e.Graphics;
 TabPage tp = TabControl1.TabPages(e.Index);
 Brush br;
 StringFormat sf = new StringFormat();
 RectangleF r = new RectangleF(e.Bounds.X, e.Bounds.Y + 2, e.Bounds.Width, e.Bounds.Height - 2);
 sf.Alignment = StringAlignment.Center;
 string strTitle = tp.Text;
 if (TabControl1.SelectedIndex == e.Index) {
   br = new SolidBrush(Color.SkyBlue);
   g.FillRectangle(br, e.Bounds);
   br = new SolidBrush(Color.Black);
   g.DrawString(strTitle, TabControl1.Font, br, r, sf);
 } else {
   br = new SolidBrush(Color.DarkGray);
   g.FillRectangle(br, e.Bounds);
   br = new SolidBrush(Color.Black);
   g.DrawString(strTitle, TabControl1.Font, br, r, sf);
 }
}


Answers (4)