private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
{
Font TabFont;
Brush BackBrush = new SolidBrush(Color.FromArgb(102,102,102)); //Set background color
Brush ForeBrush = new SolidBrush(Color.FromArgb(180,255,0));
//Brush ForeBrush = new SolidBrush(Color.Yellow);//Set foreground color
if (e.Index == this.tabControl1.SelectedIndex)
{
TabFont = new Font(e.Font,FontStyle.Regular|FontStyle.Bold );
}
else
{
TabFont = e.Font;
}
string TabName = this.tabControl1.TabPages[e.Index].Text;
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
e.Graphics.FillRectangle(BackBrush, e.Bounds);
Rectangle r = e.Bounds;
r = new Rectangle(r.X, r.Y , r.Width, r.Height);
e.Graphics.DrawString(TabName, TabFont, ForeBrush, r, sf);
//Dispose objects
sf.Dispose();
if (e.Index == this.tabControl1.SelectedIndex)
{
TabFont.Dispose();
BackBrush.Dispose();
}
else
{
BackBrush.Dispose();
ForeBrush.Dispose();
}
}
this is the code that i got from some forum , i edited it according to my own needs , but there is one problem .. i have not been able to paint the tab buttons properly using this code .. i mean its fine when i click it but when the tab is not in focus the border colors become default and it looks very ugly .. any ideas ... im attaching the screenshot ... please check that out ..
Thankyou in advance ..


Sign In
Create Account



Back to top









