当前位置: 移动技术网 > IT编程>开发语言>.net > 如何为CheckBoxList和RadioButtonList添加滚动条

如何为CheckBoxList和RadioButtonList添加滚动条

2017年12月12日  | 移动技术网IT编程  | 我要评论

混在娱乐圈1980,宝丰县卫生局,广东人事

如何给checkboxlist和radiobuttonlist添加滚动条?
继承基类checkboxlistradiobuttonlist,添加滚动属性,重写render方法即可。
属性列表:

#region 滚动控制
    private bool _showscrollbar = false;
    /// <summary>
    /// 显示滚动条
    /// </summary>
    [
    system.componentmodel.description("是否显示显示滚动条")
    , system.componentmodel.defaultvalue(false)
    , system.componentmodel.category("滚动条设置")
    , system.componentmodel.bindable(system.componentmodel.bindablesupport.yes)
    ]
    public bool showscrollbar
    {
      get { return _showscrollbar; }
      set { _showscrollbar = value; }
    }
    private overflow _overflowy = overflow.auto;
    /// <summary>
    /// 竖直滚动条
    /// </summary>
    [
    system.componentmodel.description("竖直滚动条")
    , system.componentmodel.defaultvalue(overflow.auto)
    , system.componentmodel.category("滚动条设置")
    , system.componentmodel.bindable(system.componentmodel.bindablesupport.yes)
    ]
    public overflow overflowy
    {
      get { return _overflowy; }
      set { _overflowy = value; }
    }
    private overflow _overflowx = overflow.auto;
    /// <summary>
    /// 水平滚动条
    /// </summary>
    [
    system.componentmodel.description("水平滚动条")
    , system.componentmodel.defaultvalue(overflow.auto)
    , system.componentmodel.category("滚动条设置")
    , system.componentmodel.bindable(system.componentmodel.bindablesupport.yes)
    ]
    public overflow overflowx
    {
      get { return _overflowx; }
      set { _overflowx = value; }
    }
    private unit _scrollheight = unit.parse("0px");
    /// <summary>
    /// 滚动高度
    /// </summary>
    [
    system.componentmodel.description("滚动高度")
    , system.componentmodel.category("滚动条设置")
     , 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>
    /// 滚动宽度
    /// </summary>
    [
    system.componentmodel.description("滚动宽度")
    , system.componentmodel.category("滚动条设置")
    , defaultvalue("0px")
    , system.componentmodel.bindable(system.componentmodel.bindablesupport.yes)
    ]
    public unit scrollwidth
    {
      get { return _scrollwidth; }
      set { _scrollwidth = value; }
    }
    private string _scrollcssclass = "";
    /// <summary>
    /// 滚动样式设置
    /// </summary>
    [
    system.componentmodel.description("滚动样式设置")
    , system.componentmodel.category("滚动条设置")
    , system.componentmodel.defaultvalue("")
    , system.componentmodel.bindable(system.componentmodel.bindablesupport.yes)
    ]
    public string scrollcssclass
    {
      get { return _scrollcssclass; }
      set { _scrollcssclass = value; }
    }

    #region 书写标签
    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

重写render方法: 

 protected override void render(htmltextwriter writer)
    {
      this.writebeginspan(writer);
      base.render(writer);
      this.writeendspan(writer);
    } 

就这样就可以了。
还要定义一个枚举:

public enum overflow
  {
    auto = 0,
    hidden = 1,
    scroll = 2,
    visible = 3,
    inherit = 4
  }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网