How can I retreive system colors related to current Aero style? I especially need the colors used in the selection gradient. SystemColors
structure does not contain required colors.
Alternatively: How can I use WinAPI to draw selection on the specific canvas (Graphics object)?
OK, so the answer to the initial question is: there is no way to determine the specific colors I asked for. It is evaluated by internal theming routines provided by the OS.
Fortunately, there is a way to ask the OS to draw a themed piece of control, so called part. .NET provides two classes for drawing UI:
System.Windows.Forms.VisualStyles for themed UI and
System.Windows.Forms.ControlPaint for non-themed "Windows Classic".
Selection I asked for may be drawn by the following code:
// Graphics g = ...
VisualStyleRenderer selectionRenderer = new VisualStyleRenderer(VisualStyleElement.TreeView.Item.Selected);
selectionRenderer.DrawBackground(g, someRectangle);
Unfortunately, neither TreeView.Item.Selected
, nor ListView.Item.Selected
is supported by the default window theme. However, one may switch theme to the Explorer using WinAPI via p/invoke:
// C++
SetWindowTheme(hwnd, L"Explorer", nullptr);
And then P/invoke his way through few UXTheme.h routines, which works perfectly.