Click here to Skip to main content
15,031,941 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Tabcontrol changing properties
C#
private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
        {
           Font TabFont;
Brush BackBrush = new SolidBrush(Color.Green); //Set background color
Brush ForeBrush = new SolidBrush(Color.Yellow);//Set foreground color
if (e.Index == this.tabControl1.SelectedIndex)
{
    TabFont = new Font (e.Font, FontStyle.Italic 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 + 3, r.Width, r.Height - 3);
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();
}
        }

Error is comming in this line
C#
//TabFont = new Font (e.Font, FontStyle.Italic FontStyle.Bold);
Posted
Updated 5-May-14 23:07pm
v2
Comments
Prasad Avunoori 6-May-14 5:10am
   
What is the error?
hilbert hussen 6-May-14 6:38am
   
Error 3 Invalid expression term ')'

1 solution

Don't say you just left out the pipe (or) in between FontStyle.Italic and FontStyle.Bold, and didn't spot it...

Maybe tell us what is the error?
   
v2
Comments
hilbert hussen 6-May-14 6:39am
   
Error 3 Invalid expression term ')'
johannesnestler 6-May-14 6:46am
   
So you didn't read my solution? You forgot a pipe-sign (bitwise-or)! The line should be ... new Font (e.Font, FontStyle.Italic | FontStyle.Bold); You can combine an enum defined with [Flags] attribute like this. see http://msdn.microsoft.com/en-us/library/system.flagsattribute.aspx for reference.
hilbert hussen 6-May-14 7:02am
   
Thanku
johannesnestler 6-May-14 7:08am
   
you are welcome, sorry for my first "unpolite" answer - I realy thought it was just a copy, paste error when you created the question.
hilbert hussen 6-May-14 7:10am
   
ok

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