center the font in a tab control?

  • Thread starter Thread starter Alexander Paul Lorenz
  • Start date Start date
A

Alexander Paul Lorenz

Hi there,
is there any possibility to center the titles in a tabcontrol object?
Normaly the font is alligned to the left hand side by default.
THX
 
Hi,

You have to set the tabcontrols drawmode to ownerdrawfixed. Add code
in the drawitem event to draw the title centered.

Private Sub TabControl1_DrawItem(ByVal sender As Object, ByVal e As
System.Windows.Forms.DrawItemEventArgs) Handles TabControl1.DrawItem

Dim g As Graphics = e.Graphics

Dim tp As TabPage = TabControl1.TabPages(e.Index)

Dim br As Brush

Dim sf As New StringFormat

Dim r As New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width,
e.Bounds.Height)

sf.Alignment = StringAlignment.Center

Dim strTitle As String = tp.Text

g.DrawString(strTitle, TabControl1.Font, Brushes.Black, r, sf)

End Sub

Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top