会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
Technical ViewPoint Of Derek
Derek's Studio & Derek's Zone
博客园
首页
新随笔
联系
管理
订阅
自动适应输入内容高度的TextBox控件
附 AutoTextBox 控件源码
#region
附 AutoTextBox 控件源码
using
System;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.ComponentModel;
namespace
WebExcel.UI.WebControls
{
/**/
/**/
/**/
///
<summary>
///
Summary description for AutoLengthTextBox.
///
</summary>
[DefaultProperty(
"
Text
"
),
ToolboxData(
"
<{0}:AutoTextArea runat=server></{0}:AutoTextArea>
"
)]
public
class
AutoTextArea : System.Web.UI.WebControls.TextBox
{
[DefaultValue(
200
)]
public
int
MaxHeight
{
get
{
object
obj
=
ViewState[
"
MaxHeight
"
];
return
obj
==
null
?
200
: (
int
)obj;
}
set
{
ViewState[
"
MaxHeight
"
]
=
value;
}
}
[DefaultValue(
60
)]
public
int
MinHeight
{
get
{
object
obj
=
ViewState[
"
MinHeight
"
];
return
obj
==
null
?
60
: (
int
)obj;
}
set
{
ViewState[
"
MinHeight
"
]
=
value;
}
}
protected
override
void
OnPreRender(EventArgs e)
{
this
.Attributes[
"
minHeight
"
]
=
this
.MinHeight.ToString();
if
(
this
.Height
==
Unit.Empty )
{
this
.Height
=
this
.MinHeight;
}
else
{
this
.Height
=
(
int
)Math.Max(
this
.MinHeight,
this
.Height.Value);
}
base
.OnPreRender (e);
}
/**/
/**/
/**/
///
<summary>
///
Render this control to the output parameter specified.
///
</summary>
///
<param name="output">
The HTML writer to write out to
</param>
protected
override
void
Render(HtmlTextWriter output)
{
string
strCode;
if
(
this
.MaxHeight
<=
0
)
{
strCode
=
"
this.style.height=Math.max(this.minHeight,this.scrollHeight)+(this.offsetHeight-this.clientHeight)
"
;
}
else
{
strCode
=
"
this.style.height=(this.scrollHeight>200)?200:Math.max(this.minHeight,this.scrollHeight)+(this.offsetHeight-this.clientHeight)
"
;
}
base
.Attributes[
"
onpropertychange
"
]
=
strCode;
//
base.Attributes["onfocus"] = "this.height=this.height";
if
(
base
.Rows
==
0
)
{
base
.Rows
=
1
;
}
base
.TextMode
=
TextBoxMode.MultiLine;
base
.Render(output);
}
}
}
#endregion
posted @
2007-12-12 15:47
Derek
阅读(
228
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告