How do I know the current width of system scrollbar?

C#Winforms

C# Problem Overview


As you know, one can customize the width of the scrollbar width in Display Properties -> Appearance -> Advanced -> Item: ScrollBar. The default value is 17. However, I can't assume this is always the case, is it possible for me to retrieve this value?

C# Solutions


Solution 1 - C#

Look at the System.Windows.Forms.SystemInformation class members: HorizontalScrollBarHeight and VerticalScrollBarWidth.

Solution 2 - C#

Vertical Scroll Bar Width

System.Windows.Forms.SystemInformation.VerticalScrollBarWidth;

Solution 3 - C#

If you want to know the size of a ScrollableControl minus the size of the scroll bar, the easiest way is to use the Control.ClientSize property.

From the documentation:

> Gets or sets the height and width of the client area of the control. The client area of a control is the bounds of the control, minus the nonclient elements such as scroll bars, borders, title bars, and menus.

Solution 4 - C#

Skip the ClientSize property of the control. At least in VS2013 the Scrollbar is included in the ClientSize.

When I formatted a RichTextBox with a width of 304 and a vertical scrollbar, the Client Size width was 300, which only accounted for the borders.

stick with the System.Windows.Forms.SystemInformation.VerticalScrollBarWidth to get your scrollbar width.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHao Wooi LimView Question on Stackoverflow
Solution 1 - C#leppieView Answer on Stackoverflow
Solution 2 - C#user256251View Answer on Stackoverflow
Solution 3 - C#Paolo MView Answer on Stackoverflow
Solution 4 - C#user3892767View Answer on Stackoverflow