特色栏目

ASP源码

PHP源码

.NET源码

JSP源码

游戏频道
专题合集
关闭菜单
首页> ASP.NET教程> 自动处理过长字符串显示的Web控件

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

时间:2009-06-30 16:00:51 作者:互联网

    我们很多时候需要在一行上显示一段说明文字,而由于Web页面宽度的不确定性,我们任意调节其宽度后,常常搞得文字撑出页面或者折成好多行。通过使用CSS,我们可以限制为一行的宽度,并使多余的字符隐藏。为了方便,做成一个小Web控件来使用。
    using System;
using Sy***m.Web.UI;
using Sy***m.Web.UI.WebControls;
using Sy***m.ComponentModel;

namespace cn***gs.birdshome.WebControls
{
    /**////


    /// Summary description for AutoLabel.
    ///

    [DefaultProperty("Text"),
        ToolboxData("<{0}:AutoLabel runat=server>")]
    public class AutoLabel : Sy***m.Web.UI.WebControls.Label
    {
        protected override void CreateChildControls()
        {
            ba***CreateChildControls ();
            th***Width = Un***Percentage(100);
            th***Attributes["onmouseover"] =
                 "if ( th***clientWidth < th***scrollWidth ) th***title = th***innerText; else th***title = '';";
            th***Attributes.CssStyle["white-space"] = "nowrap";
            th***Attributes.CssStyle["overflow"] = "hidden";
            th***Attributes.CssStyle["text-overflow"] = "ellipsis";
        }
    }
}
    AutoLabel继承至Label控件,默认宽度为"100%",当把AutoLabel放入容器类元素中后,其内容的宽度受容器大小自动调整。并且当AutoLabel出现"..."号后,鼠标放在上面,其ToolTip会自动显示器完整内容。 如下图:
   AutoLabel.gif

相关文章 最新文章

相关应用

热门文章

猜你喜欢

返回顶部