|
-
Dec 7th, 2003, 12:30 AM
#1
Thread Starter
Addicted Member
HowTo: Select Tab Caption Bold?
I am tryin to set the text of the selected tab to bold but theres no property to do this so I tried to override the drawing of the tabs.
VB Code:
private void tab_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
tabArea = tab.GetTabRect(e.Index);
tabTextArea = (RectangleF)tab.GetTabRect(e.Index);
StringFormat drawFormat = new StringFormat();
drawFormat.Alignment = StringAlignment.Center;
SolidBrush b = new SolidBrush(Color.Black);
Graphics g = e.Graphics;
Pen p = new Pen(Color.White);
System.Drawing.Font font;
if (e.Index == tab.SelectedIndex)
{
font = new Font(tab.Font.FontFamily,tab.Font.Size , FontStyle.Bold, GraphicsUnit.Point);
}
else
{
font = tab.Font;
g.DrawRectangle(p, tabArea);
}
g.DrawString(tab.TabPages[e.Index].Text, font, b, tabTextArea, drawFormat);
}
I have a few problems with this. One is it puts the text at the top of the tab instead of the middle I'm not sure how to fix that. Second it's writting the text as multiline. Third i draw the line but with pen but don't know how to keep it from appearing under the selected tab. But the bold works Does anyone kno how i can fix these problems or another way of doing this?
Last edited by Tewl; Dec 7th, 2003 at 01:13 AM.
-
Dec 7th, 2003, 04:21 AM
#2
Sleep mode
Look up how to use MeasureString .
Code:
Graphics gfx;
gfx.MeasureString
-
Dec 7th, 2003, 06:28 PM
#3
Thread Starter
Addicted Member
Thanks pirate I'm having some trouble with that method tho. I have been reading on msdn and it seemed that I needed to measure the string then adjust the rectanges width and height but I am having problems with this.
VB Code:
private void tab_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
tabArea = tab.GetTabRect(e.Index);
StringFormat drawFormat = new StringFormat();
drawFormat.Alignment = StringAlignment.Center;
drawFormat.LineAlignment = StringAlignment.Center;
SolidBrush b = new SolidBrush(Color.Black);
Pen p = new Pen(Color.White);
Font font = tab.Font;
if (e.Index == tab.SelectedIndex)
{
p = new Pen(this.BackColor);
font = new Font(tab.Font.FontFamily,tab.Font.Size , FontStyle.Bold, GraphicsUnit.Point);
/*
SizeF stringSize = new SizeF();
stringSize = e.Graphics.MeasureString(tab.TabPages[e.Index].Text, font);
tabArea.Width = (int)stringSize.Width;
tabArea.Height = (int)stringSize.Height;
*/
}
e.Graphics.DrawRectangle(p, tabArea);
e.Graphics.DrawString(tab.TabPages[e.Index].Text, font, b, (RectangleF)tabArea, drawFormat);
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|