Resolved How to extract colors from ProfessionalColorTable

aaaron

Well-known member
Joined
Jan 23, 2011
Messages
216
Programming Experience
10+
I'm looking at MS' code

public class ProfessionalColorTable

and see many tables of color:



'Private void InitCommonColors(ref Dictionary<knowncolors, color> rgbTable)
'internal void InitSystemColors(ref Dictionary<knowncolors, color> rgbTable)
'internal void InitOliveLunaColors(ref Dictionary<knowncolors, color> rgbTable)
'internal void InitSilverLunaColors(ref Dictionary<knowncolors, color> rgbTable)
'Private void InitRoyaleColors(ref Dictionary<knowncolors, color> rgbTable)
'internal void InitThemedColors(ref Dictionary<knowncolors, color> rgbTable)
'internal void InitBlueLunaColors(ref Dictionary<knowncolors, color> rgbTable)



I can see the color definitions and would like to extract the tables but can't figure out how to do that.

If I could use VB.Net to enumerate using Reflection somehow to get the entries that would be great.

Got any suggestions as to how I can do that?



The above is what I really need but if you happen to know anything about

DisplayInformation.LowResolution

which I see used there but never set, I'm curious about that.



I
 
VB.NET:
Dim table As New ProfessionalColorTable
Dim mInfo = table.GetType.GetMethod("InitBlueLunaColors", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance)
Dim pType = mInfo.GetParameters(0).ParameterType
Dim typeArgs = pType.GetGenericArguments
Dim genericType = GetType(Dictionary(Of ,)).MakeGenericType(typeArgs)
Dim dict = CType(Activator.CreateInstance(genericType), IDictionary)
mInfo.Invoke(table, {dict})

Dim aKey = System.Enum.Parse(typeArgs(0), "msocbvcrWPText")
Dim aValue = dict(aKey)
 
Amazing! So close but I havn't been able to enumerate all the colors in a table.
I keep bumpig up against KnoenColors enum is marked internal. At least that is what I think my problem is.
Can you enumerate all the colors in a table.
I see that to get a key you hard coded "msocbvcrWPText"
I've been trying to get that string programmatically and can't fid the way.
 
VB.NET:
For Each key In dict.Keys
    Dim name = System.Enum.GetName(key.GetType, key)
    Dim value = dict(key)
Next
or
VB.NET:
Dim names = System.Enum.GetNames(typeArgs(0))
 
Something happened going from .Net Framework to .Net.

Maybe the method "InitSilverLunaColors" was renamed or removed.

I don't know how to check further.

Any suggestions?


Untitled.jpg
 
The code (post 2) work fine for me with .Net 6, also for "InitSilverLunaColors".
 
I ran ito problems a few weeks ago but didn't post then hoping to work it out.

Now I don't remember enough of what I did to be precise.

Also: This post should have been in:

Use my Renderer and select one of the ProfessionalColorTables color sets​


I'm was paying around with vs2022 preview and .Net 8 and got other errors before the one I posted here.

I believe I simply chaged 6.0 to 8.0 in your vbproj file.

I got an error that two output files resolve to the same path.

I don't remember how but I must have found a way around it (most likely causing the error posted here).
 
It is a .Net Framework 4.8 project in that thread.

There is in fact a change from .Net 6 to .Net 7, the three Init...LunaColors methods has changed from instance to shared. (BindingFlags.Instance to BindingFlags.Static)
 
Back
Top