110

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?

Hao Wooi Lim
  • 3,928
  • 4
  • 29
  • 35

4 Answers4

159

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

Frank Krueger
  • 69,552
  • 46
  • 163
  • 208
leppie
  • 115,091
  • 17
  • 196
  • 297
36

Vertical Scroll Bar Width

System.Windows.Forms.SystemInformation.VerticalScrollBarWidth;
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
11

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.

Paolo M
  • 12,403
  • 6
  • 52
  • 73
  • 3
    Unfortunately, ClientSize also includes the width of the scrollbar (yields same value as ActualWidth). Doesn't make sense though. – Oyvind Jun 09 '16 at 08:07
2

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.