When per-monitor DPI changes (WM_DPICHANGED
message), the built-in scrollbars of controls like list view, tree view, rich edit, listbox are not scaled (as expected).
They need to be scaled programmatically.
Though I didn't find any API (neither in Win32, let alone in WinForms) to set scrollbar size.
What API can I use to set scrollbar size (width)?
Or at least how I do get hold of the scrollbar handle? (I assume that internally the scrollbars are separate child controls) Once I have the handle, I assume I can use MoveWindow
to resize it (Edit: my assumption was incorrect, as the answer by @Anders shows)
For a background, see High DPI Desktop Application Development on Windows.
There are couple seemingly duplicate questions, but none of them are actually relevant:
The answers there either change system-wide settings or work for DataGrid
only (that have separate child scrollbar controls available in its interface).
The scrollbar-width property is used to set the width or thickness of an element's scrollbar when shown. This property can be used on pages where the user interface requires the element to be displayed more prominently and shrinking the scrollbar width gives more space to the element.
The default scrollbar width can range anywhere from 12px to 17px. Webkit browsers also have the ability for the user to configure scrollbar widths. Webkit browsers, such as Chrome can have custom scrollbars that can have any size scrollbar.
To get the width of the scrollbar, you use the offsetWidth and clientWidth of the Element : The offsetWidth returns the width of the Element in pixels including the scrollbar. The clientWidth returns the with of the Element in pixels without the scrollbar.
scrollbar-width accepts the following values: auto is the default value and will render the standard scrollbars for the user agent. thin will tell the user agent to use thinner scrollbars, when applicable. none will hide the scrollbar completely, without affecting the element's scrollability.
Scrollbars are usually not separate windows. If a window uses the WS_HSCROLL
/WS_VSCROLL
styles then the scrollbars are implemented in the non-client area of the control itself.
Windows 10 Creators Update is going to introduce something called Per Monitor V2 DPI awareness. This includes child window notifications, "Windows Forms DPI scaling improvements" and "Improved theming behavior". It is also going to automatically scale the non-client area.
In the meantime you can try calling EnableNonClientDpiScaling
in WM_NCCREATE
(added in the Anniversary Update).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With