How to draw UI elements with Visual Styles turned off?
-
24-02-2021 - |
문제
I have a owner drawn control where I need to draw the expand box ("plus/minus") of a treeview. With visual styles turned on it is easy, just create a renderer for the appropriate VisualStyleElement:
VisualStyleElement element = VisualStyleElement.TreeView.Glyph.Opened
VisualStyleRenderer renderer = new VisualStyleRenderer( element );
Size size = renderer.GetPartSize( graphics, ThemeSizeType.True );
...
renderer.DrawBackground( graphics, someRect );
Is it possible to achieve a similar effect when visual styles are off? I know there is a ControlPaint class which can draw entire controls, but how do I draw (and get the size of) just a part of the TreeView control?
해결책
Without VisualStyles, I think the plus minus controls are just DrawRectangle and DrawLine method calls.
The Rectangle part looks like it uses the SystemColors.Control
color, and the Plus/Minus part looks like SystemColors.ControlText
(or black).
제휴하지 않습니다 StackOverflow