⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 itemimage.cs

📁 一个ASP.NET下的中文内容管理和社区系统
💻 CS
字号:
namespace ASPNET.StarterKit.Communities {

    using System;
    using System.Collections;
    using System.Web.UI;
    using System.Web.UI.WebControls;


    //*********************************************************************
    //
    // ItemImage Class
    //
    // Displays an image retrieved from a database table. Enables 
    // you to generate an image with a specific width and height
    // by setting the Width and Height properties.
    // 
    // Notice that this is an abstract class. It is implemented by
    // ItemBookImage, ItemPhotoImage, ItemEventImage, etc.
    //
    //*********************************************************************
    
    public abstract class ItemImage : Control {

        private int _width = -1;
        private int _height = -1;
        private string _align = "middle";
        private int _border = 1;
        private string _cssClass = "itemImage";


        //*********************************************************************
        //
        // ItemImage Constructor
        //
        // Disable view state by default. 
        //
        //*********************************************************************
        public ItemImage() : base() {
            EnableViewState = false;
        }



        //*********************************************************************
        //
        // Width Property
        //
        // Represents the width of the image. 
        //
        //*********************************************************************

        public int Width { 
            get { return _width; }
            set {_width = value;}
        }


        //*********************************************************************
        //
        // Height Property
        //
        // Represents the height of the image. 
        //
        //*********************************************************************
    
        public int Height {
            get { return _height; }
            set { _height = value;}
        }


        //*********************************************************************
        //
        // Align Property
        //
        // Represents the alignment of the image. 
        //
        //*********************************************************************
    
        public string Align {
            get { return _align; }
            set { _align = value;}
        }


        //*********************************************************************
        //
        // Border Property
        //
        // Represents the border size of the image. 
        //
        //*********************************************************************
    
        public int Border {
            get { return _border; }
            set { _border = value;}
        }    



        //*********************************************************************
        //
        // CssClass Property
        //
        // Represents the css class of the image. 
        //
        //*********************************************************************
    
        public string CssClass {
            get { return _cssClass; }
            set { _cssClass = value;}
        }    




        //*********************************************************************
        //
        // ImageUrl Property
        //
        // The URL of the image. 
        //
        //*********************************************************************

        public string ImageUrl {
            get {
                if (ViewState["ImageUrl"] == null)
                    return String.Empty;
                else
                    return (string)ViewState["ImageUrl"];
            }
            
            set {ViewState["ImageUrl"] = value;}
        }        


        //*********************************************************************
        //
        // NavigateUrl Property
        //
        // When set, the image acts as a hyperlink. 
        //
        //*********************************************************************

        public string NavigateUrl {
            get {
                if (ViewState["NavigateUrl"] == null)
                    return String.Empty;
                else
                    return (string)ViewState["NavigateUrl"];
            }
            set {ViewState["NavigateUrl"] = value;}
        }


        //*********************************************************************
        //
        // Render Method
        //
        // Renders the <img> tag to the browser. 
        //
        //*********************************************************************
  
        protected override void Render(HtmlTextWriter tw) {
            // Don't render anything when no url
            if (ImageUrl == String.Empty)
                return;
        
            // Build Query String
            ArrayList colParams = new ArrayList();
            
            // Add Width
            if (_width != -1)
                colParams.Add( String.Format("Width={0}", _width) );
                
            // Add Height
            if (Height != Unit.Empty)
                colParams.Add( String.Format("Height={0}", _height) );
                
                
            // Build image URL           
            for (int i=0;i < colParams.Count;i++) {
                if (i==0)
                    ImageUrl += "?" + colParams[i];
                else
                    ImageUrl += "&" + colParams[i];
            }

            if (NavigateUrl != String.Empty) {
                tw.AddAttribute(HtmlTextWriterAttribute.Class, "itemImageLink");
                tw.AddAttribute(HtmlTextWriterAttribute.Href, NavigateUrl);
                tw.RenderBeginTag(HtmlTextWriterTag.A);
            }    
                  
            tw.Write(String.Format("<img src=\"{0}\" align=\"{1}\" border=\"{2}\" class=\"{3}\" />", ImageUrl, _align, _border, _cssClass));      
            
            if (NavigateUrl != String.Empty)
                tw.RenderEndTag();
       
        }



    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -