Thank you for taking the time to help me.
I am using PowerShell to build a GUI and I would like to override default system colors.
For example, when a control is highlighted (TextBox or ComboBox), form shows system colors. I would like to change the color to use AliceBlue. So far I have tried following codes, but to no avail:
[System.Drawing.SystemColors]::Highlight = 'AliceBlue'
[System.Drawing.SystemColors]::HighlightText = 'AliceBlue'
[System.Drawing.SystemColors]::ScrollBar = 'AliceBlue'
[System.Drawing.SystemColors]::Control = 'AliceBlue'
[System.Drawing.SystemColors]::HotTrack = 'AliceBlue'
[System.Drawing.SystemColors]::Window = 'AliceBlue'
[System.Drawing.SystemColors]::WindowFrame = 'AliceBlue'
The documentation says that those properties you are trying to set are readonly.
You can do this by invoking the
user32.dllSetSysColorsfunction:Where the
13element representsCOLOR_HIGHLIGHT, which is the colour of an item selected in a control.After running the above code, here is the result:
ComboBox
TextBox
You can see that the colour of the actual text has changed and it is barely visible. To change this, simply run:
Where
14representsCOLOR_HIGHLIGHTTEXT, which is the colour of the text of an item selected in a control.To see more about
SetSysColorscheck PInvoke. Also, go here to find more color codes.I don't know if it is possible to set the highlight colour for only the PowerShell GUI and nothing else using
WinFormsorSetSysColor, but one way you might consider is by using aWPFTextBoxinstead ofWinForms. This way you can useSelectionBrushandSelectionOpacity: