C# 如何知道系统滚动条的当前宽度?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/856917/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I know the current width of system scrollbar?
提问by Hao Wooi Lim
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?
众所周知,可以在Display Properties -> Appearance -> Advanced -> Item: ScrollBar 中自定义滚动条的宽度。默认值为 17。但是,我不能假设情况总是如此,我是否可以检索此值?
采纳答案by leppie
Look at the System.Windows.Forms.SystemInformation
class members: HorizontalScrollBarHeight
and VerticalScrollBarWidth
.
看看System.Windows.Forms.SystemInformation
班级成员:HorizontalScrollBarHeight
和VerticalScrollBarWidth
。
回答by leppie
Vertical Scroll Bar Width
垂直滚动条宽度
System.Windows.Forms.SystemInformation.VerticalScrollBarWidth;
回答by Paolo M
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.
如果你想知道 aScrollableControl
的大小减去滚动条的大小,最简单的方法是使用该Control.ClientSize
属性。
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.
获取或设置控件工作区的高度和宽度。控件的客户区是控件的边界,减去非客户元素,如滚动条、边框、标题栏和菜单。
回答by user3892767
Skip the ClientSize property of the control. At least in VS2013 the Scrollbar is included in the ClientSize.
跳过控件的 ClientSize 属性。至少在 VS2013 中,滚动条包含在 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.
当我格式化一个宽度为304,垂直滚动条的RichTextBox时,Client Size宽度为300,只占了边框。
stick with the System.Windows.Forms.SystemInformation.VerticalScrollBarWidth to get your scrollbar width.
坚持使用 System.Windows.Forms.SystemInformation.VerticalScrollBarWidth 来获取滚动条宽度。