自动处理过长字符串显示的Web控件

翻译|其它|编辑:郝浩|2006-06-02 10:34:00.000|阅读 1607 次

概述:

# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>


我们很多时候需要在一行上显示一段说明文字,而由于Web页面宽度的不确定性,我们任意调节其宽度后,常常搞得文字撑出页面或者折成好多行。通过使用CSS,我们可以限制为一行的宽度,并使多余的字符隐藏。为了方便,做成一个小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会自动显示器完整内容。



标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP