views:

2167

answers:

2

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.

+2  A: 

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.

John Rudy
A: 

An easy way to give tab controls different labels depending on a field value is to change the caption itself:

For example:

Private Sub Form_Current() If IsNull(Me.Subform.Form.Field_Name) Then Me.Tab_Name.Caption = "Tab One" Else Me.Tab_Name.Caption = "Tab One +++" End If