How can I get the height of horizontal and/or width of vertical scrollbar that appears on control (e.g. DataGridView)?
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.
The default scrollbar width can range anywhere from 12px to 17px.
Use:
SystemInformation.HorizontalScrollBarHeight;
SystemInformation.VerticalScrollBarWidth;
The scrollbars that appear on your DataGridView will be the same horizontal height and vertical width as all of the other scrollbars on your computer. These sizes are defined by the active Windows theme, and exposed by the .NET Framework in the following properties of the SystemInformation
class:
VerticalScrollBarWidth
HorizontalScrollBarHeight
The same class also provides additional information about the default scrollbar parameters in the current system environment.
If you need to know which scrollbars are currently visible on your control, use its ScrollBars
property. This gets or sets one of the ScrollBars
values, either None
, Horizontal
, Vertical
, or Both
.
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