自动处理过长字符串显示的Web控件
2006-11-28 13:09
381 查看
我们很多时候需要在一行上显示一段说明文字,而由于Web页面宽度的不确定性,我们任意调节其宽度后,常常搞得文字撑出页面或者折成好多行using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace cnblogs.birdshome.WebControls
{
/**//// <summary>
/// Summary description for AutoLabel.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:AutoLabel runat=server></{0}:AutoLabel>")]
public class AutoLabel : System.Web.UI.WebControls.Label
{
protected override void CreateChildControls()
{
base.CreateChildControls ();
this.Width = Unit.Percentage(100);
this.Attributes["onmouseover"] =
"if ( this.clientWidth < this.scrollWidth ) this.title = this.innerText; else this.title = '';";
this.Attributes.CssStyle["white-space"] = "nowrap";
this.Attributes.CssStyle["overflow"] = "hidden";
this.Attributes.CssStyle["text-overflow"] = "ellipsis";
}
}
}
AutoLabel继承至Label控件,默认宽度为"100%",当把AutoLabel放入容器类元素中后,其内容的宽度受容器大小自动调整。并且当AutoLabel出现"..."号后,鼠标放在上面,其ToolTip会自动显示器完整内容。 如下图:
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace cnblogs.birdshome.WebControls
{
/**//// <summary>
/// Summary description for AutoLabel.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:AutoLabel runat=server></{0}:AutoLabel>")]
public class AutoLabel : System.Web.UI.WebControls.Label
{
protected override void CreateChildControls()
{
base.CreateChildControls ();
this.Width = Unit.Percentage(100);
this.Attributes["onmouseover"] =
"if ( this.clientWidth < this.scrollWidth ) this.title = this.innerText; else this.title = '';";
this.Attributes.CssStyle["white-space"] = "nowrap";
this.Attributes.CssStyle["overflow"] = "hidden";
this.Attributes.CssStyle["text-overflow"] = "ellipsis";
}
}
}
AutoLabel继承至Label控件,默认宽度为"100%",当把AutoLabel放入容器类元素中后,其内容的宽度受容器大小自动调整。并且当AutoLabel出现"..."号后,鼠标放在上面,其ToolTip会自动显示器完整内容。 如下图:
相关文章推荐
- 【转】 自动处理过长字符串显示的Web控件。
- 自动处理过长字符串显示的Web控件
- 自动处理过长字符串显示的Web控件
- 自动处理过长字符串显示的Web控件
- 自定义文字滚动控件,用于单行文本的显示,当文字过长的时候,就会自动的向左滚动
- 字符串过长显示处理
- [BS-01] 根据字符串对象的参数自动计算用来显示该字符串的UI控件的宽和高
- 样式表自动截断字符串、省略显示不出来的字符,不用服务器端处理,也不会出现乱码
- 样式表自动截断字符串、省略显示不出来的字符,不用服务器端处理,也不会出现乱码
- 控件文字过长的显示处理
- ireport报表制作, 当一个字段显示的数据太多时(数据过长),则需要自动换行
- Web服务启动时自动加载Servlet,并执行service处理 监听处理
- web.config中配置字符串中特殊字符的处理
- 基于MVC+EasyUI的Web开发框架经验总结(17)--布局和对话框自动适应大小的处理
- django 模板html自动转义符号和处理字符串在序列中自动加u
- Label显示数据过长的处理方式
- DataBind包括三大方法,Repeater,DataList和DataGrid,这些控件都位于 System.Web.UI.WebControls 命名空间中,从 WebControl 基类中直接或间接派生出来的。这些方法都是通过HTML来显示数据的内
- Android下WebView的图片适配加载与文字自动换行处理
- web.config中配置字符串中特殊字符的处理
- RDIFramework.NET框架Web中datagrid与treegrid控件自动生成右键菜单与列标题右键菜单