How to add a scroll bar for CheckBoxList and RadioButtonList-practical tips

Source: Internet
Author: User


How do I add scroll bars to CheckBoxList and RadioButtonList?
inherits the base class CheckBoxList and RadioButtonList , Add scrolling properties and rewrite the Render method.
Properties list:


#region scroll control
    private bool _ShowScrollBar = false;
    /// <summary>
    /// show scroll bar
    /// </ summary>
    [
    System.ComponentModel.Description ("Whether to show the scroll bar")
    , System.ComponentModel.DefaultValue (false)
    , System.ComponentModel.Category ("Scroll bar settings")
    , System.ComponentModel.Bindable (System.ComponentModel.BindableSupport.Yes)
    ]
    public bool ShowScrollBar
    {
      get {return _ShowScrollBar;}
      set {_ShowScrollBar = value;}
    }
    private Overflow _OverflowY = Overflow.auto;
    /// <summary>
    /// vertical scroll bar
    /// </ summary>
    [
    System.ComponentModel.Description ("Vertical scroll bar")
    , System.ComponentModel.DefaultValue (Overflow.auto)
    , System.ComponentModel.Category ("Scroll bar settings")
    , System.ComponentModel.Bindable (System.ComponentModel.BindableSupport.Yes)
    ]
    public Overflow OverflowY
    {
      get {return _OverflowY;}
      set {_OverflowY = value;}
    }
    private Overflow _OverflowX = Overflow.auto;
    /// <summary>
    /// horizontal scroll bar
    /// </ summary>
    [
    System.ComponentModel.Description ("Horizontal scroll bar")
    , System.ComponentModel.DefaultValue (Overflow.auto)
    , System.ComponentModel.Category ("Scroll bar settings")
    , System.ComponentModel.Bindable (System.ComponentModel.BindableSupport.Yes)
    ]
    public Overflow OverflowX
    {
      get {return _OverflowX;}
      set {_OverflowX = value;}
    }
    private Unit _ScrollHeight = Unit.Parse ("0px");
    /// <summary>
    /// scroll height
    /// </ summary>
    [
    System.ComponentModel.Description ("Scroll height")
    , System.ComponentModel.Category ("Scroll bar settings")
     , 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>
    /// scroll width
    /// </ summary>
    [
    System.ComponentModel.Description ("Scroll width")
    , System.ComponentModel.Category ("Scroll bar settings")
    , DefaultValue ("0px")
    , System.ComponentModel.Bindable (System.ComponentModel.BindableSupport.Yes)
    ]
    public Unit ScrollWidth
    {
      get {return _ScrollWidth;}
      set {_ScrollWidth = value;}
    }
    private string _ScrollCssClass = "";
    /// <summary>
    /// scroll style settings
    /// </ summary>
    [
    System.ComponentModel.Description ("Scroll style settings")
    , System.ComponentModel.Category ("Scroll bar settings")
    , System.ComponentModel.DefaultValue ("")
    , System.ComponentModel.Bindable (System.ComponentModel.BindableSupport.Yes)
    ]
    public string ScrollCssClass
    {
      get {return _ScrollCssClass;}
      set {_ScrollCssClass = value;}
    }

    #region Writing tags
    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


To override the Render method:


 protected override void Render (HtmlTextWriter writer)
    {this
      . Writebeginspan (writer);
      Base. Render (writer);
      This. Writeendspan (writer);
    } 


That's it for you.
You also define an enumeration:


Public enum Overflow
  {
    auto = 0,
    hidden = 1,
    scroll = 2,
    visible = 3,
    inherit = 4
  }


The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.