在项目的过程中,我们经常需要显示flash image,视频等一些东西做为banner等。
这个时候我们希望有一个控件,像Image一样直要传给它ImageUrl就可以自动显示出合适的东西
[Designer("System.Web.UI.Design.WebControls.PreviewControlDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[DefaultProperty("ImageUrl")]
[ToolboxData("<{0}:MultiMedia runat=server></{0}:MultiMedia>")]
public class MultiMedia : Image
{
![](/Images/OutliningIndicators/InBlock.gif)
public FileType FileType = FileType.Other;
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
protected virtual void CalculateType()
{
if (!string.IsNullOrEmpty(ImageUrl))
{
int start = ImageUrl.LastIndexOf('.');
string type = ImageUrl.Substring(start, ImageUrl.Length - start).ToLower();
if (type == ".swf")
{
FileType = FileType.Flash;
}
else
{
FileType = FileType.Image;
}
}
}
![](/Images/OutliningIndicators/InBlock.gif)
protected override void Render(HtmlTextWriter writer)
{
CalculateType();
switch(FileType)
{
case FileType.Image:
base.Render(writer);
break;
case FileType.Flash:
RenderFlash(writer);
break;
}
}
![](/Images/OutliningIndicators/InBlock.gif)
public virtual void RenderFlash(HtmlTextWriter output)
{
![](/Images/OutliningIndicators/InBlock.gif)
string url = this.ResolveUrl(ImageUrl);
output.Write("<embed src='"+url+"' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='"+this.Width+"' height='"+this.Height+"' wmode='Opaque'></embed>");
![](/Images/OutliningIndicators/InBlock.gif)
}
}
![](/Images/OutliningIndicators/None.gif)
public enum FileType
{
Image,
Flash,
Other,
}
}
也许你发现了。什么在选择的时候没有发现*.swf 这个时候我们可以自己扩展
public class MediaUrlFilter : System.Web.UI.Design.UrlEditor
{
![](/Images/OutliningIndicators/InBlock.gif)
protected override string Filter
{
get
{
return "MultiType (*.swf *.jpg *.gif) |*.swf;*.gif;*.jpg;*.png|All files|*.*";
}
}
}
并重写
[Editor(typeof(MediaUrlFilter),typeof(System.Drawing.Design.UITypeEditor))]
public override string ImageUrl
{
get
{
return base.ImageUrl;
}
set
{
base.ImageUrl = value;
}
}
这样我们就可以发现了。
注意:System.Web.UI.Design 这个命名空间在 System.Design.dll里。需要使用browser把它加进来
一些需要用到的东西可以自己扩展
ADD:
public virtual void RenderVideo(HtmlTextWriter output)
{
output.NewLine = "\r\n";
string url = this.ResolveUrl(ImageUrl);
output.Write("<embed src='"+url+"' border='0' width='"+this.Width+"' height='"+this.Height+"' type='application/x-mplayer2'></embed>");
}
这个时候我们希望有一个控件,像Image一样直要传给它ImageUrl就可以自动显示出合适的东西
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
也许你发现了。什么在选择的时候没有发现*.swf 这个时候我们可以自己扩展
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
并重写
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
注意:System.Web.UI.Design 这个命名空间在 System.Design.dll里。需要使用browser把它加进来
一些需要用到的东西可以自己扩展
ADD:
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)