如何為CheckBoxList和RadioButtonList添加滾動(dòng)條
來(lái)源:易賢網(wǎng) 閱讀:827 次 日期:2016-08-05 15:25:15
溫馨提示:易賢網(wǎng)小編為您整理了“如何為CheckBoxList和RadioButtonList添加滾動(dòng)條”,方便廣大網(wǎng)友查閱!

這篇文章主要介紹了為CheckBoxList和RadioButtonList添加滾動(dòng)條的方法,感興趣的小伙伴們可以參考一下

如何給CheckBoxList和RadioButtonList添加滾動(dòng)條?

繼承基類(lèi)CheckBoxList和RadioButtonList,添加滾動(dòng)屬性,重寫(xiě)Render方法即可。

屬性列表:

#region 滾動(dòng)控制

    private bool _ShowScrollBar = false;

    /// <summary>

    /// 顯示滾動(dòng)條

    /// </summary>

    [

    System.ComponentModel.Description("是否顯示顯示滾動(dòng)條")

    , System.ComponentModel.DefaultValue(false)

    , System.ComponentModel.Category("滾動(dòng)條設(shè)置")

    , System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.Yes)

    ]

    public bool ShowScrollBar

    {

      get { return _ShowScrollBar; }

      set { _ShowScrollBar = value; }

    }

    private Overflow _OverflowY = Overflow.auto;

    /// <summary>

    /// 豎直滾動(dòng)條

    /// </summary>

    [

    System.ComponentModel.Description("豎直滾動(dòng)條")

    , System.ComponentModel.DefaultValue(Overflow.auto)

    , System.ComponentModel.Category("滾動(dòng)條設(shè)置")

    , System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.Yes)

    ]

    public Overflow OverflowY

    {

      get { return _OverflowY; }

      set { _OverflowY = value; }

    }

    private Overflow _OverflowX = Overflow.auto;

    /// <summary>

    /// 水平滾動(dòng)條

    /// </summary>

    [

    System.ComponentModel.Description("水平滾動(dòng)條")

    , System.ComponentModel.DefaultValue(Overflow.auto)

    , System.ComponentModel.Category("滾動(dòng)條設(shè)置")

    , System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.Yes)

    ]

    public Overflow OverflowX

    {

      get { return _OverflowX; }

      set { _OverflowX = value; }

    }

    private Unit _ScrollHeight = Unit.Parse("0px");

    /// <summary>

    /// 滾動(dòng)高度

    /// </summary>

    [

    System.ComponentModel.Description("滾動(dòng)高度")

    , System.ComponentModel.Category("滾動(dòng)條設(shè)置")

     , DefaultValue("0px")

    , System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.Yes)

    ]

    public Unit ScrollHeight

    {

      get { return _ScrollHeight; }

      set { _ScrollHeight = value; }

    }

    private Unit _ScrollWidth = Unit.Parse("0px");

    /// <summary>

    /// 滾動(dòng)寬度

    /// </summary>

    [

    System.ComponentModel.Description("滾動(dòng)寬度")

    , System.ComponentModel.Category("滾動(dòng)條設(shè)置")

    , DefaultValue("0px")

    , System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.Yes)

    ]

    public Unit ScrollWidth

    {

      get { return _ScrollWidth; }

      set { _ScrollWidth = value; }

    }

    private string _ScrollCssClass = "";

    /// <summary>

    /// 滾動(dòng)樣式設(shè)置

    /// </summary>

    [

    System.ComponentModel.Description("滾動(dòng)樣式設(shè)置")

    , System.ComponentModel.Category("滾動(dòng)條設(shè)置")

    , System.ComponentModel.DefaultValue("")

    , System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.Yes)

    ]

    public string ScrollCssClass

    {

      get { return _ScrollCssClass; }

      set { _ScrollCssClass = value; }

    }

    #region 書(shū)寫(xiě)標(biāo)簽

    void WriteBeginSpan(HtmlTextWriter writer)

    {

      if (this._ShowScrollBar)

      {

        StringBuilder strSpan = new StringBuilder();

        strSpan.Append("<span ");

        strSpan.Append(string.Format("style='overflow-y:{0};overflow-x:{1};",

          System.Enum.GetName(typeof(Overflow), this._OverflowY),

          System.Enum.GetName(typeof(Overflow), this._OverflowX)));

        if (this._ScrollHeight.ToString() != "0px")

        {

          strSpan.Append(string.Format("height:{0};", this._ScrollHeight));

        }

        if (this._ScrollWidth.ToString() != "0px")

        {

          strSpan.Append(string.Format("width:{0};", this._ScrollWidth));

        }

        strSpan.Append("';");

        if (!string.IsNullOrEmpty(_ScrollCssClass))

        {

          strSpan.Append(string.Format(" class='{0}'", _ScrollCssClass));

        }

        strSpan.Append(">");

        writer.Write(strSpan.ToString());

      }

    }

    void WriteEndSpan(HtmlTextWriter writer)

    {

      if (this._ShowScrollBar)

      {

        writer.Write("</span>");

      }

    }

    #endregion

    #endregion

重寫(xiě)Render方法: 

protected override void Render(HtmlTextWriter writer)

   {

     this.WriteBeginSpan(writer);

     base.Render(writer);

     this.WriteEndSpan(writer);

   } 

就這樣就可以了。

還要定義一個(gè)枚舉:

public enum Overflow

  {

    auto = 0,

    hidden = 1,

    scroll = 2,

    visible = 3,

    inherit = 4

  }

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助

更多信息請(qǐng)查看網(wǎng)絡(luò)編程
易賢網(wǎng)手機(jī)網(wǎng)站地址:如何為CheckBoxList和RadioButtonList添加滾動(dòng)條
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢(xún)回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門(mén)公布的正式信息和咨詢(xún)?yōu)闇?zhǔn)!
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢(xún) | 簡(jiǎn)要咨詢(xún)須知 | 加入群交流 | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專(zhuān)用圖標(biāo)
聯(lián)系電話:0871-65317125(9:00—18:00) 獲取招聘考試信息及咨詢(xún)關(guān)注公眾號(hào):hfpxwx
咨詢(xún)QQ:526150442(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專(zhuān)用圖標(biāo)