开发者

How to change the Font and/or Color of a selected TabPage?

I've been Googling, testing, etc for a couple hours and I'm right where I started off. the WinForms TabControl sucks... Does anyone have tips or code to make it so when I select a TabPage, the font or color changes?

I've messed around with the draw commands and while that does work, it draws the borders/backgrounds so they are very old / outdated looking.

This is basically for a simple tab text editor I'm working on when a Te开发者_StackOverflow中文版xtBox in the control changes I can update the associated tab with either a red font or just bold it to indicate the TextBox on that TabPage is modified.

I've definitely be open for alternative TabControl as long as they are free and come with a VB.Net example.

This is in VB.Net 2008 Express.


Set the TabControl drawmode to OwnerDrawFixed then create a eventhandler to paint the tabs in response to the DrawItem event. e.g.

Private Sub TabControl1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles TabControl1.DrawItem
  Dim tabctl As TabControl = DirectCast(sender, TabControl)
  Dim g As Graphics = e.Graphics
  Dim font As Font = tabctl.Font
  Dim brush As New SolidBrush(Color.Black)
  tabTextArea = RectangleF.op_Implicit(tabctl.GetTabRect(e.Index))
  If tabctl.SelectedIndex = e.Index Then
    font = New Font(font, FontStyle.Bold)
    brush = New SolidBrush(Color.Red)
  End If
  g.DrawString(tabctl.TabPages(e.Index).Text, font, brush, tabTextArea)
End Sub


Set the DrawMode of the tab control to OwnerDrawFixed and paint the tabs yourself in response to the DrawItem event.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜