虽然现在网上可以找到n多第三方控件,可我总是看那些单独的dll不爽,在微软提供的标准控件无法满足实际需求时,大多采取扩展标准控件定制个性功能的方法解决,本文描述了给ImageButton控件增加鼠标悬浮变换图像功能的实现步骤。——cncxz(虫虫) 2006-3-22 安装上vs.net2005之后,就发现asp.net2.0中的主题和外观功能用起来比较方便,例如ImageButton控件,只要在不同主题下的外观文件(*.Skin)中设置好相应的imageurl属性,在更换主题时做好SkinID关联的ImageButton控件就会指向不同的图片了。后来看到QuickStart中“运行”、“查看源代码”两个按钮效果后,就想,加上一个鼠标悬浮变换图像的功能是不是更好一点?
首先查看了一下QuickStart中的实现代码,发现它是直接在Html中作的构造:
<
a
target
="<%=_target%>"
href
="<%=RunSample%>"
>
<
img
alt
="Run Sample"
border
="0"
src
="<%=HttpRuntime.AppDomainAppVirtualPath%>/images/button_run.gif"
onmouseout
="this.src='<%=HttpRuntime.AppDomainAppVirtualPath%>/images/button_run.gif'"
onmouseover
="this.src='<%=HttpRuntime.AppDomainAppVirtualPath%>/images/button_run-over.gif'"
onmousedown
="this.src='<%=HttpRuntime.AppDomainAppVirtualPath%>/images/button_run-down.gif'"
onmouseup
="this.src='<%=HttpRuntime.AppDomainAppVirtualPath%>/images/button_run.gif'"
/></
a
>
于是使用Reflector反编译System.Web.dll,找到ImageButton的源码,原来ImageButton就是一个实现了IPostBackDataHandler、IPostBackEventHandler、IButtonControl三个接口的Image,打开Image的源码,看到了如下的ImageUrl属性定义代码:
[WebCategory(
"
Appearance
"
), Editor(
"
System.Web.UI.Design.ImageUrlEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
"
,
typeof
(UITypeEditor)), DefaultValue(
""
), UrlProperty, Bindable(
true
), WebSysDescription(
"
Image_ImageUrl
"
)]
public
virtual
string
ImageUrl 
{
get 
{
string text1 = (string) this.ViewState["ImageUrl"];
if (text1 != null) 
{
return text1;
}
return string.Empty;
}
set 
{
this.ViewState["ImageUrl"] = value;
}
}
public
virtual
string
ImageOverUrl 
{
get 
{
string text1 = (string)this.ViewState["ImageOverUrl"];
if (text1 != null) 
{
return text1;
}
return string.Empty;
}
set 
{
this.ViewState["ImageOverUrl"] = value;
}
}