?? itemimage.cs
字號(hào):
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();
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -