You can use reflection. Inspired by this link , my code will look something like this. (This may be too careful, but I'm not sure how it would be with reflection. For example, VScrollBar was not found for the TextBox in 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() ); }
source share