[导入]给当前选中的控件提供高亮显示功能

想要的效果是让当前选中的控件有一个高亮的效果.
要实现这个功能要先有一个给控件添一个 Attributes 的方法.
#region SetInputControlsHighlight
/// <summary>
/// 设置当控件得到焦点的时候,控件的样式.
/// </summary>
/// <param name="container"> 指定的控件. </param>
/// <param name="className"> 应用样式的样式名称 </param>
/// <param name="onlyTextBoxes"> 是否只允许TextBox有这个属性. </param>
public static void SetInputControlsHighlight(Control container,
string className, bool onlyTextBoxes)
{
foreach (Control ctl in container.Controls)
{
// 在if里面可以加想要的控件.
if ((onlyTextBoxes && ctl is TextBox) || ctl is TextBox ||
ctl
is DropDownList || ctl is ListBox || ctl is CheckBox ||
ctl
is RadioButton || ctl is RadioButtonList || ctl is CheckBoxList)
{
WebControl wctl
= ctl as WebControl;
wctl.Attributes.Add(
" onfocus " , string .Format(
" this.className = '{0}'; " , className));
wctl.Attributes.Add(
" onblur " , " this.className = ''; " );
}
else
{
if (ctl.Controls.Count > 0 )
SetInputControlsHighlight(ctl, className, onlyTextBoxes);
}
}
}
#endregion
为了要个控件添加这个属性.要重写Onload();
protected override void OnLoad(EventArgs e)
{
// add onfocus and onblur javascripts to all input controls on the forum,
// so that the active control has a difference appearance
// 设置当前空间的样式.
Helpers.SetInputControlsHighlight( this , " highlight " , false );
base .OnLoad(e);
}
别忘了还要有一个样式单:
/* **********************************************
/ 设置当前选中控件的样式.
/**********************************************
*/
.highlight
{
background-color
: #fefbd2 ;
color
: #000080 ;
}

文章来源: http://link-to.cn/post/2007/12/activeControlHighlight.aspx

转载于:https://www.cnblogs.com/sliuqin/archive/2007/12/05/1018815.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值