zoukankan      html  css  js  c++  java
  • 可以变换图像的ImageButton

    项目中。我们经常需要一个当鼠标移过去就可以变换图像,离开又恢复到原来图像的控件,
    也许大家都会说easy 但是这个写多起来也是比较郁闷。所以我们还是自己来写一个控件

      internal sealed class WebCategoryAttribute : System.ComponentModel.CategoryAttribute
        
    {

            
    internal WebCategoryAttribute(string category)
                : 
    base(category)
            
    {
            }


          

        }
     // class WebCategoryAttribute
        /// <summary>
        
    /// Summary description for MyImageButton
        
    /// </summary>

        public class MyImageButton : ImageButton
        
    {
            [Editor(
    "System.Web.UI.Design.ImageUrlEditor, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"typeof(System.Drawing.Design.UITypeEditor))]
            [DefaultValue(
    "")]
            [WebCategoryAttribute(
    "Appearance")]
            [Bindable(
    true)]
            
    public string HoverImageUrl
            
    {
                
    get
                
    {
                    
    string text = (string)this.ViewState["HoverImageUrl"];
                    
    if (text != null)
                    
    {
                        
    return text;
                    }

                    
    return string.Empty;

                }

                
    set
                
    {
                    
    this.ViewState["HoverImageUrl"= value;
                }

            }

            
    protected override void AddAttributesToRender(HtmlTextWriter writer)
            
    {
                
    if (HoverImageUrl.Length != 0)
                
    {
                    
    base.Attributes.Add("onmouseover"string.Format("this.src=\"{0}\""base.ResolveUrl(HoverImageUrl)));
                    
    base.Attributes.Add("onmouseout"string.Format("this.src=\"{0}\""base.ResolveUrl(ImageUrl)));
                }

                
    base.AddAttributesToRender(writer);
            }

            
    public MyImageButton()
            
    {

            }

        }

    }

    很简单就可以搞定了。 比较复杂的地方是。HoverImageUrl 你必须为它指定一个Editor
  • 相关阅读:
    二叉树进阶之寻找一棵二叉树中的最大二叉搜索子树
    二叉树进阶之求一棵二叉树中结点间最大距离
    软件工程各阶段的UML图
    软件工程各阶段的开发文档
    二叉树应用进阶之折纸(二叉树的右根左遍历)
    二叉树进阶应用之查找结点的后继结点
    二叉树进阶之满二叉树和完全二叉树
    二叉树进阶之搜索二叉树的判断与找出搜索二叉树中出错的结点
    二叉树进阶之平衡二叉树的判断
    二叉树基础之序列化和反序列化二叉树
  • 原文地址:https://www.cnblogs.com/lovebanyi/p/897460.html
Copyright © 2011-2022 走看看