1 Replies - 18732 Views - Last Post: 14 September 2009 - 01:28 AM Rate Topic: -----

#1 JohnorSky  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 137
  • Joined: 02-September 08

How to change color of tabpage tab?

Posted 13 September 2009 - 08:41 PM

I have tabpage1.backcolor = black and that doesn't change the color of the tab itself.. the tab is still gray.. How do you change the colors of the tabs themselves?

I think this will do..: http://www.programme...93/tab-control/

This post has been edited by JohnorSky: 13 September 2009 - 08:57 PM

Is This A Good Question/Topic? 0
  • +

Replies To: How to change color of tabpage tab?

#2 Luc001  Icon User is offline

  • D.I.C Addict

Reputation: 84
  • View blog
  • Posts: 617
  • Joined: 04-May 09

Re: How to change color of tabpage tab?

Posted 14 September 2009 - 01:28 AM

Hi,

You could try this:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

		TabControl1.DrawMode = TabDrawMode.OwnerDrawFixed

	End Sub

Add this sub to your program. It colors the Tab (not the page) the same colors as the background of the tab, if it is the one selected. The other tabs are colored a standard white with black text. You can modify it anyway you want, but it seems to work very well for coloring the tabs.

	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 + 2,e.Bounds.Width, e.Bounds.Height - 2)

		sf.Alignment = StringAlignment.Center

		Dim strTitle As String = tp.Text

		'If the current index is the Selected Index, change the color

		If TabControl1.SelectedIndex = e.Index Then

			'this is the background color of the tabpage

			'you could make this a stndard color for the selected page

			br = New SolidBrush(tp.BackColor)

			'this is the background color of the tab page

			g.FillRectangle(br, e.Bounds)

			'this is the background color of the tab page

			'you could make this a stndard color for the selected page

			br = New SolidBrush(tp.ForeColor)

			g.DrawString(strTitle, TabControl1.Font, br, r, sf)

		Else

			'these are the standard colors for the unselected tab pages

			br = New SolidBrush(Color.WhiteSmoke)

			g.FillRectangle(br, e.Bounds)

			br = New SolidBrush(Color.Black)

			g.DrawString(strTitle, TabControl1.Font, br, r, sf)

		End If

	End Sub

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1