VB .NET

Listing 2. The AlteredColorTable class builds on the ToolstripProfessionalColorTable to provide a variety of UI colors relative to a base and selected color. A default for the selected color provides a good look in many situations. You could extend this class to handle additional colors, infer text colors, or explicitly supply some colors.

Option Strict On
Option Explicit On

Imports System
Imports System.Drawing
Imports System.Windows.Forms

Public Class AlteredColorTable
	Inherits BaseApplicationColorTable

	Private mBaseColor As Color
	Private mSelectedColor As Color

	Private mToolbarForeColor As Color
	Private mControlBackColor As Color
	Private mWindowBackColor As Color
	Private mControlText As Color
	Private mWindowText As Color

	Public Sub New(ByVal baseColor As Color)
		Me.mBaseColor = baseColor
	End Sub

	Public Property BaseColor() As Color
		Get
			Return mBaseColor
		End Get
		Set(ByVal value As Color)
			mBaseColor = value
		End Set
	End Property

	Public Property SelectedColor() As Color
		Get
			If mSelectedColor = Drawing.Color.Empty Then
				Return ButtonSelectedGradientMiddle
			End If
			Return mSelectedColor
		End Get
		Set(ByVal value As Color)
			mSelectedColor = value
		End Set
	End Property

	Public Overrides ReadOnly Property _
		ToolbarForeColor() As Color
		Get
			If mToolbarForeColor = Drawing.Color.Empty Then
				Return SystemColors.ControlText
			End If
		Return mToolbarForeColor
		End Get
	End Property

	Public Overrides ReadOnly Property ControlBackColor() _
		As Color
		Get
			If mControlBackColor = _
				Drawing.Color.Empty Then
				Return ControlPaint.Light( _
					ToolStripGradientEnd, 0.9)
			End If
			Return mControlBackColor
		End Get
	End Property

	Public Overrides ReadOnly _
		Property WindowBackColor() As Color
		Get
			If mWindowBackColor = Drawing.Color.Empty Then
				Return ControlPaint.Light( _
					ToolStripGradientBegin)
			End If
			Return mWindowBackColor
		End Get
	End Property

	Public Overrides ReadOnly Property ControlText() _
		As Color
		Get
			If mControlText = Drawing.Color.Empty Then
				Return SystemColors.ControlText
			End If
			Return mControlText
		End Get
	End Property

	Public Overrides ReadOnly Property WindowText() As Color
		Get
			If mWindowText = Drawing.Color.Empty Then
				Return SystemColors.WindowText
			End If
				Return mWindowText
		End Get
	End Property

#Region "Overrides of base color table requests"
	Public Overrides ReadOnly Property _
		MenuStripGradientBegin() _
	As System.Drawing.Color
		Get
			If mBaseColor = Drawing.Color.Empty Then
				Return MyBase.MenuStripGradientBegin
			End If
				Return mBaseColor
			End Get
	End Property

	Public Overrides ReadOnly Property _
		RaftingContainerGradientBegin() _
		As System.Drawing.Color
		Get
			Return mBaseColor
		End Get
	End Property


	Public Overrides ReadOnly Property _
		ToolStripGradientBegin() As System.Drawing.Color
		Get
			Return ControlPaint.Light(mBaseColor, 1)
		End Get
	End Property

	Public Overrides ReadOnly Property _
		ToolStripGradientMiddle() As System.Drawing.Color
		Get
			Return mBaseColor
		End Get
	End Property

	Public Overrides ReadOnly Property _
		ToolStripGradientEnd() As System.Drawing.Color
		Get
			Return ControlPaint.Dark(mBaseColor, 0)
		End Get
	End Property

#End Region
End Class