如何在DataGridView控件上获取滚动条的大小?

时间:2010-12-16 16:06:14

标签: c# winforms datagridview controls scrollbar

如何获得控件上显示的垂直滚动条的水平和/或宽度(例如DataGridView)?

3 个答案:

答案 0 :(得分:11)

使用:

SystemInformation.HorizontalScrollBarHeight;
SystemInformation.VerticalScrollBarWidth;

答案 1 :(得分:6)

DataGridView上显示的滚动条与计算机上所有其他滚动条的水平高度和垂直宽度相同。这些大小由活动Windows主题定义,并由.NET Framework在SystemInformation class的以下属性中公开:

同一类还提供有关当前系统环境中默认滚动条参数的其他信息。


如果您需要知道哪个滚动条当前在您的控件上可见,请使用其ScrollBars property。这将获取或设置ScrollBars values之一,NoneHorizontalVerticalBoth

答案 2 :(得分:-1)

将其放在资源字典中:

<xcdg:DataGridControl >
<xcdg:DataGridControl.Resources>
<Style TargetType="{x:Type xcdg:TableViewScrollViewer}">
<Setter Property="VerticalScrollBarVisibility" Value="Hidden" />
</Style>
</xcdg:DataGridControl>

<击>

检查一下:

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.scrollbars.aspx

无论此属性的值如何,只有在需要时才会显示滚动条。使用此属性可防止出现滚动条。例如,当您想要提供用于滚动的备用用户界面(UI)时,这很有用。

http://msdn.microsoft.com/en-us/library/system.windows.forms.scrollbars.aspx