Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bold text for a tab control

I'd like to bold the text for a tab page under certain conditions (not, necessarily, GotFocus). Is it true the only 'er easiest way to do this is by overriding the DrawItem event for the tab control?

http://www.vbforums.com/showthread.php?t=355093

It seems like there should be an easier way.

Like ...

tabControl.TabPages(index).Font = New Font(Me.Font, FontStyle.Bold)

That doesn't work, obviously.

like image 695
MattH Avatar asked Oct 07 '08 21:10

MattH


1 Answers

When you set the Font property on a TabPage, you are setting the default font for all controls on that tab page. You are not setting it for the header, however.

When you execute the following code:

tabControl.TabPages(index).Font = New Font(Me.Font, FontStyle.Bold)

Any controls on that page will now be bold by default, which is not (I'm assuming) what you want.

The header's font (that is, the tab itself) is controlled by the TabControl's Font property. If you were to change your code to:

tabControl.Font = New Font(Me.Font, FontStyle.Bold)

You will see that in action. However, it changes the font for all the tabs on display, which is also not, I'm assuming, what you want.

So, using the default WinForms tab control, you are (I believe) limited to the technique in the link you've posted. Alternatively, you can begin looking at 3rd-party controls, such as those discussed in these questions on StackOverflow.

like image 85
John Rudy Avatar answered Sep 27 '22 22:09

John Rudy