VScrollBar Width in Compact Framework
Unfortunately, the SystemInformation.VerticalScrollBarWidth member is not available in the .NET Compact Framework. Knowing this value is incredibly useful when you want to resize DataGrid columns whether the vertical scrollbar is visible or not.
Simply hard-coding the width to 13 pixels is not a good idea, considering devices with higher resolution render the VScrollBar wider. And using p/invoke calls like GetSystemMetrics are never very elegant.
However, I came across a cool way to simply search for the VScrollBar in the control and check whether it's visible.
int GetVerticalScrollBarWidth(Control parent)
{
foreach (Control control in parent.Controls)
{
if (control is VScrollBar && control.Visible)
However, I came across a cool way to simply search for the VScrollBar in the control and check whether it's visible.
int GetVerticalScrollBarWidth(Control parent)
{
foreach (Control control in parent.Controls)
{
if (control is VScrollBar && control.Visible)
return control.Width;
}
return 0;
}
This works really slick for DataGrid in the Compact Framework. And there was great rejoicing!
}
return 0;
}
This works really slick for DataGrid in the Compact Framework. And there was great rejoicing!










0 comments:
Post a Comment