如何知道系统滚动条的当前宽度?

如您所知,可以在 Display Properties-> 卖相-> Advanced-> Item: ScrollBar 中自定义滚动条宽度。默认值是17。但是,我不能假设总是这样,我是否有可能检索到这个值?

57254 次浏览

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

Vertical Scroll Bar Width

System.Windows.Forms.SystemInformation.VerticalScrollBarWidth;

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.

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.