我在一个自定义控件中用Style类存储控件的样式。
但是怎么把里面的内容提取出来添加到render中去呢?

解决方案 »

  1.   

    也就是 Style style = new Style();
    style.Width = 200;
    style.BackColor = System.Drawing.Color.FromArgb(200,10,200);我怎么的到style里面存储的样式的字符串表现形式呢?
    也就是类似于 "width=200px;bgcolor=xxx"一类的字符串。
      

  2.   

    给Style类加索引器,循环遍历索引,
    把每个属性的名字和值加入字符串中
      

  3.   

    你先看tostring方法實現了沒有?如果沒有就自己跌代咯。
      

  4.   

    ms-help://MS.MSDNQTR.2004APR.1033/cpref/html/frlrfsystemwebuiwebcontrolsstyleclasstopic.htm
      

  5.   

    ms-help://MS.MSDNQTR.2004APR.1033/cpref/html/frlrfsystemwebuiwebcontrolsstyleclassaddattributestorendertopic.htm
      

  6.   

    to: greennetboy(我的老婆叫静静)
    没有2004的MSDN,我的只有03和05年的.
      

  7.   

    using System;
    using System.Web;
    using System.Web.UI;
    public class MyControl:Control
    private Style _style=new Style();
    public MyControl()
    {
       this._style.Width = 200;
       this._style.BackColor = System.Drawing.Color.FromArgb(200,10,200);
    }
    protected override void Render(HtmlTextWriter writer)
    {
       this._style.AddAttributesToRender(writer);//这句就完成你了要求
       base.Render(writer);
       
    }
      

  8.   

    string style = "";
    System.Collections.IEnumerator keys = Style.Keys.GetEnumerator();
    while (keys.MoveNext()) 
    {
    style += (string)keys.Current + ":" + Style[(string)keys.Current] + ";";
    }