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会自动显示器完整内容。 如下图:
查看全文
相关阅读:
C# 6.0
C# 4.0
C# 5.0
C# 3.0
C# 2.0
C# 1.0(2002)
字典树Trie
Hadoop——生态体系
程序是怎样跑起来的
Redis实战(十七)Redis各个版本新特性
原文地址:https://www.cnblogs.com/levin/p/575030.html
最新文章
js/jquery获取浏览器窗口可视区域高度和宽度以及滚动条高度实现代码
window.onload()与$(document).ready()区别
bootstrap注意事项(八)一些辅助信息
bootstrap注意事项(七)图片
bootstrap注意事项(六)按钮
内容为空弹出提示框
css3选择器
bootstrap注意事项(五)表单
兼容所有浏览器的CSS3圆角
rem vh vw vmin vmax ex ch
热门文章
Reverse Words in a String
Linux执行.sh文件Permission denied
PHP trait
mysql find_in_set
Linux crontab
Redis缓存
Linux学习
Linux进程
php 二维数组自定义排序
nginx 资源重定向
Copyright © 2011-2022 走看看