翱翔.Net

释放.Net的力量
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Web自定义控件FlashLabel

Posted on 2005-02-28 08:59  Hover  阅读(4191)  评论(8编辑  收藏  举报
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace Hover.WebControls
{
    
/// <summary>
    
/// FlashLabel 的摘要说明。
    
/// Description:文字闪烁的Label控件
    
/// WebSite:IT动力营 Http://ITHero.NET 
    
/// Author:翱翔.Net(Hover)
    
/// Email:zytp@163.com
    
/// MSN:Zytp@MSN.Com
    
/// Blog:Http://CnBlogs.Com/Hover
    
/// </summary>

    [DefaultProperty("Text"), 
    ToolboxData(
"<{0}:FlashLabel runat=server ></{0}:FlashLabel>")]
    
public class FlashLabel : System.Web.UI.WebControls.Label
    
{
        
private int flashSpeed=100;
        [Bindable(
true), 
        Category(
"Appearance"), 
        DefaultValue(
""),
        Description(
"文字闪烁速度!")] 
            
        
public int FlashSpeed
        
{
            
get
            
{
                
return flashSpeed;
            }


            
set
            
{
                flashSpeed
=value;
            }

        }

        

        
/// <summary> 
        
/// 将此控件呈现给指定的输出参数。
        
/// </summary>
        
/// <param name="output"> 要写出到的 HTML 编写器 </param>

        protected override void Render(HtmlTextWriter output)
        
{
            
string s;
            
string scriptString="<script language=JavaScript> \n";
            scriptString
+="function glowit(which){ \n"
            scriptString
+="if (document.all.glowtext.filters[0].strength==2) \n ";
            scriptString
+="document.all.glowtext.filters[0].strength=1 \n";
            scriptString
+="else  \n";
            scriptString
+="document.all.glowtext.filters[0].strength=2 } \n";
            scriptString
+="function startglowing(){ \n";
            scriptString
+="var fp='"+this.FlashSpeed+"'; \n";
            scriptString
+=@"setInterval(""glowit(0)"",fp)}";            
            scriptString
+=" \n window.onload=startglowing \n";
            scriptString
+="</script>";
            s
=string.Format(@"<div  id=glowtext style=""FILTER: glow(color={0},strength=2); WIDTH: 5%"">{1}</div>",new object[]{this.ForeColor.Name,this.Text});
            output.Write(scriptString);
            output.Write(s);
        }

    }

}