Bold text for a tab control

I would like to highlight text for bookmarks on certain conditions (not necessarily GotFocus). Is it true that the only easy way to do this is to override the DrawItem event for the tab control?

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

There seems to be an easier way.

How...

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

This does not work, obviously.

+6
winforms
source share
3 answers

When you set the Font property to TabPage, you set the default font for all the controls on this tab. However, you do not set it for the header.

When executing the following code:

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

Any controls on this page will now be in bold, which is not (I assume) what you want.

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

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

You will see it in action. However, it changes the font for all tabs displayed, and also not, I assume you want.

So, using the default WinForms tab control, you (I suppose) are limited by the technique in the link you specify. In addition, you can begin to review third-party controls, such as those discussed in these questions on StackOverflow .

+5
source share

A simple way to specify tabs of various labels depending on the field value is to change the label 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 End Sub 
+1
source share
 private void tabControl1_DrawItem(object sender, DrawItemEventArgs e) { Font BoldFont = new Font(tabControl1.Font, FontStyle.Bold); e.Graphics.DrawString(tabControl1.TabPages[e.Index].Text, BoldFont, Brushes.Black, e.Bounds); } private void Form1_Paint(object sender, PaintEventArgs e) { tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed; } 
+1
source share

All Articles