通过反射设置私有属性

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;
}
posted @ 2013-07-26 10:02  pnljs  阅读(374)  评论(0编辑  收藏  举报