• 可以变换图像的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
  • 相关阅读:
    数据结构--链表基础练习题
    LeetCode 10.28每日一题1207. 独一无二的出现次数【简单】
    数据结构--链表
    LeetCode 10.25每日一题845. 数组中的最长山脉【中等】
    LeetCode 10.22每日一题763. 划分字母区间【中等】
    解决map热点与uni-app中map标签冲突的问题。(Vue Render函数应用)
    【Codeforces 1329A】Dreamoon Likes Coloring
    【Codeforces Alpha Round #20 C】Dijkstra?
    【 Educational Codeforces Round 93 (Rated for Div. 2) D】Colored Rectangles
    【Codeforces Round #643 (Div. 2) C】Count Triangles
  • 原文地址:https://www.cnblogs.com/lovebanyi/p/897460.html
Copyright © 2020-2023  润新知