Is it possible to use my Renderer which inherits ToolStripProfessionalRenderer, passing a ProfessionalColorTable, and I select the KnownColors in the ProfessionalColorTable setto be used (for example, InitOliveLunaColors)
ProfessionalColorTable
with .Net Reflector (ILSpy could also be used) and use some regex to extract the overridable properties, those that return the color to use, and output these to a xml file. There are 56 such properties that almost all look like this:Public Overridable ReadOnly Property ButtonCheckedGradientEnd As Color
Get
Return Me.FromKnownColor(KnownColors.msocbvcrCBGradSelectedEnd)
End Get
End Property
Partial Public Class CustomProfessionalColorTable
<#
Dim doc As XDocument = XDocument.Load(Host.ResolvePath("bin/Debug/properties.xml"))
For Each prop As XElement In doc...<Property>
#>
Public Overrides ReadOnly Property <#= prop.<Name>.Value #> As Color
Get
<#= prop.<Return>.Value #>
End Get
End Property
<#
Next
#>
End Class
Partial Public Class CustomProfessionalColorTable
Public Overrides ReadOnly Property ButtonCheckedGradientBegin As Color
Get
Return Me.FromKnownColor(KnownColors.msocbvcrCBGradSelectedBegin)
End Get
End Property
ProfessionalColorTable
and adds the FromKnownColor
method:Partial Public Class CustomProfessionalColorTable
Inherits ProfessionalColorTable
Private ColorTable As New Dictionary(Of KnownColors, Color)
Private Function FromKnownColor(color As KnownColor) As Color
Return ColorTable.Item(color)
End Function
Public Sub InitThemeColors(theme As ColorTheme)
End Sub
End Class
InitThemeColors
basically contains the reflection code I posted in your other thread Question - How to extract colors from ProfessionalColorTableKnownColors
enum, so I copied that plain from ProfessionalColorTable
class where it is declared Friend
(only accessible within that assembly). So "my" definition and that definition contains the same values, but are different types. After the reflection code that initialize a dictionary with the color table I copy it "locally" to this class:For Each key In dict.Keys
ColorTable(CInt(key)) = dict(key)
Next
ColorTheme
that is used to select the theme, and by reflection code to call the friend methods, for example InitOliveLunaColors
.Public Enum ColorTheme
BlueLuna
OliveLuna
SilverLuna
Themed
End Enum
CustomProfessionalColorTable
can be created and initialized with the different color themes, and use with ToolStripProfessionalRenderer
.Dim customtable As New CustomProfessionalColorTable
customtable.InitThemeColors(ColorTheme.OliveLuna)
Me.ToolStrip1.Renderer = New ToolStripProfessionalRenderer(customtable)
ProfessionalColorTable
source code and regex extraction code is also included in attachment by the way.Dim bflags = If(theme = ColorTheme.Themed, BindingFlags.Instance, BindingFlags.Static) Or BindingFlags.NonPublic
Dim mInfo = table.GetType.GetMethod(methodname, bflags)