zoukankan
html css js c++ java
自动处理过长字符串显示的Web控件
我们很多时候需要在一行上显示一段说明文字,而由于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会自动显示器完整内容。 如下图:
查看全文
相关阅读:
解决云服务器ECS,windows server 2012不能安装SQL Server 2012,不能安装.NET Fromework 3.5
html5中checkbox的选中状态的设置与获取
sql server 韩文查询匹配失败
管理nuget程序包中搜索不到任何程序包
ftp下出现“当前的安全设置不允许从该位置下载文件”提示
windows server 2012 下IIS8.5关于“ 配置错误 不能在此路径中使用此配置节”的解决办法
服务器升级后访问网站资源返回404
centos7yum的更新与优化
linux(centos7)命令提示符优化
检查vmware虚拟软件服务是否开启?
原文地址:https://www.cnblogs.com/levin/p/575030.html
最新文章
理解Ajax
MySQL配置主主及主从备份
第三方登录的原理
单点登录原理与简单实现
[微信小程序]聊天对话(文本,图片)的功能(完整代码附效果图)
Redis事务介绍
python中类的定义
python中try...excpet多种使用方法
python中try...except的用法
python中提取字典中的键值
热门文章
MyBatis批量删除
MyBatis之Oracle、Mysql批量插入
Centos7安装MySQL
Centos7安装Python3.7
安装sqlite3
Centos7安装防火墙firewall
Centos7安装Openresty和orange
配置SSH密码登录
Centos7机器信息查看
解决Win10 中打开VS2012 出现“ASP.NET 4.0 尚未在 Web 服务器上注册”
Copyright © 2011-2022 走看看