请教一下如何将 "System.Drawing.Brushes.Black" 转成 Brush    我使用以下方法不成功
    System.Reflection.Assembly assembly = System.Reflection.Assembly.GetAssembly(typeof(System.Drawing.Brushes));
    string systempath = assembly.Location;    Brush myBrushes = (Brush)Assembly.LoadFrom(systempath).CreateInstance("System.Drawing.Brushes.Black");

解决方案 »

  1.   

    System.Drawing.Brushes.Black
    是静态的,你无法创建。
      

  2.   

    那有什么办法把字符串"System.Drawing.Brushes.Black"转成Brush没有,如果可以转的话,程序就灵活多了
      

  3.   

    System.Reflection.Assembly assembly = System.Reflection.Assembly.GetAssembly(typeof(System.Drawing.Brushes));
    string systempath = assembly.Location;
    Assembly drawing = Assembly.LoadFrom(systempath);            
    Type brushes_type = drawing.GetType("System.Drawing.Brushes");
    Brush br = brushes_type.GetProperty("Black").GetGetMethod().Invoke(null,null) as Brush;
      

  4.   

    string s1 = "Black";PropertyInfo pi = typeof(Brushes).GetProperty(s1);
    if (pi != null)
    {
        Brush b1 = pi.GetValue(null, null) as Brush;
    }
      

  5.   

    静态的属性不能创建实例的,但你可以创建Color的实例啊:            Color col = new Color();
                string colStr = "System.Drawing.Brushes.Black";
                string [] colNameArr=colStr.Split(new char[]{'.'});
                col.Name = colStr[colNameArr.Length];
                SolidBrush brush = new SolidBrush(col);
      

  6.   

    wuyazhe,gomoku的方法也不错!!!实现方式有很多种。
      

  7.   

    汗,我开始认为Brushes是个枚举,用GetMember找成员去了...
      

  8.   

    楼主到底要实现什么功能呢?要转换其它思路来实现。
    如果是想做创建画刷的工厂,用自定义的类存Color、width等。
    Brush b = new SolidBrush(Color.Black, 1);
      

  9.   


    你这段有问题哦,
    错误 1 无法对属性或索引器“System.Drawing.Color.Name”赋值 -- 它是只读的