通过反射设置私有属性

private void SetEnable(bool flag)
{
    Type type = this.richEditControl1.GetType(); //ric即RichEditControl实例              
    PropertyInfo info = type.GetProperty("HorizontalScrollBar", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
    ScrollBarBase vs = (ScrollBarBase)info.GetValue(richEditControl1, null);
    vs = (ScrollBarBase)info.GetValue(richEditControl1, null);
    vs.Enabled = flag;           
    vs.ScrollBarAutoSize = true;
    //info = type.GetProperty("VerticalScrollBar", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);          
    //vs.Enabled = true;
}

你可能感兴趣的:(反射)