夜的第七章

WEB开发个人博客。

« 状态栏居中显示 Global.asax »

支持flash的AdRotator

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Text;
using System.Web;

namespace System.Web.Control
{
    /// <summary>
    /// 支持.SWF的AD
    /// </summary>
    [DefaultProperty("Text"),
     ToolboxData("<{0}:FlashAdRotator runat=server></{0}:FlashAdRotator>")]
    public class FlashAdRotator : System.Web.UI.WebControls.AdRotator
    {
        private string text;
        private bool isFlashAD;
        private string ImgUrl;
        private string NavUrl;

        [Bindable(true),
         Category("Appearance"),
         DefaultValue("")]
        public string Text
        {
            get
            {
                return text;
            }

            set
            {
                text = value;
            }
        }

        /// <summary>
        /// 将此控件呈现给指定的输出参数。
        /// </summary>
        /// <param name="output"> 要写出到的 HTML 编写器 </param>
        protected override void Render(HtmlTextWriter output)
        {
            if (this.isFlashAD)
            {
                StringBuilder StrFormat = new StringBuilder("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'");
                StrFormat.Append("codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width={0} height={1}>");
                StrFormat.Append("<param name='movie' value={2}>");
                StrFormat.Append("<param name='quality' value='high'>");
                StrFormat.Append("<embed src={3} quality='high'");
                StrFormat.Append("pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash'></embed></object>");
                StringBuilder strOutPut = new StringBuilder();
                strOutPut.AppendFormat(StrFormat.ToString(), this.Width, this.Height, this.ImgUrl, this.ImgUrl);
                output.Write(strOutPut.ToString());
            }
            else
            {
                base.Render(output);
            }
        }

        protected override void OnAdCreated(AdCreatedEventArgs e)
        {
            base.OnAdCreated(e);
            if (e.ImageUrl.ToLower().IndexOf(".swf") != 1)
            {
                this.isFlashAD = true;
                this.ImgUrl = e.ImageUrl;
                this.NavUrl = e.NavigateUrl;

            }
            else
            {
                this.isFlashAD = false;
            }
        }

    }
    public class FlashAdRotatorDesigner : System.Web.UI.Design.WebControls.AdRotatorDesigner
    {

    }

}



发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。



[2007 - 2011] © Leadnt.com