You can use reflection. Inspired by this link, my code would look something like this.
(It may be a bit too careful, but I am not so sure how generic this would be with reflection. E.g. the VScrollBar is not found for a TextBox on this form.)
using System.Reflection;
//...
public static void SetVerticalScrollbarWidth(Control c, int w)
{
try
{
var lGridVerticScrollBar = GetNonPublicFieldByReflection<VScrollBar>(c, "m_sbVert");
lGridVerticScrollBar.Width = w;
}
catch
{
// fail soft
}
}
public DataGridForm()
{
SetVerticalScrollbarWidth(dataGrid, 30);
}
public static T GetNonPublicFieldByReflection<T>(object o, string name)
{
if (o != null)
{
Type lType = o.GetType();
if (lType != null)
{
var lFieldInfo = lType.GetField(name, BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance);
if (lFieldInfo != null)
{
var lFieldValue = lFieldInfo.GetValue(o);
if (lFieldValue != null)
{
return (T)lFieldValue;
}
}
}
}
throw new InvalidCastException("Error in GetNonPublicFieldByReflection for " + o.ToString() );
}