最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

如何为CheckBoxList和RadioButtonList添加滚动条

来源:懂视网 责编:小采 时间:2020-11-27 22:36:55
文档

如何为CheckBoxList和RadioButtonList添加滚动条

如何为CheckBoxList和RadioButtonList添加滚动条:如何给CheckBoxList和RadioButtonList添加滚动条? 继承基类CheckBoxList和RadioButtonList,添加滚动属性,重写Render方法即可。 属性列表: #region 滚动控制 private bool _ShowScrollBar = false; /// <su
推荐度:
导读如何为CheckBoxList和RadioButtonList添加滚动条:如何给CheckBoxList和RadioButtonList添加滚动条? 继承基类CheckBoxList和RadioButtonList,添加滚动属性,重写Render方法即可。 属性列表: #region 滚动控制 private bool _ShowScrollBar = false; /// <su

如何给CheckBoxList和RadioButtonList添加滚动条?
继承基类CheckBoxList和RadioButtonList,添加滚动属性,重写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
 }

文档

如何为CheckBoxList和RadioButtonList添加滚动条

如何为CheckBoxList和RadioButtonList添加滚动条:如何给CheckBoxList和RadioButtonList添加滚动条? 继承基类CheckBoxList和RadioButtonList,添加滚动属性,重写Render方法即可。 属性列表: #region 滚动控制 private bool _ShowScrollBar = false; /// <su
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top