现在的位置: 首页 > 综合 > 正文

(原创)自已实现服务器控件 之 简单的Label控件

2012年03月11日 ⁄ 综合 ⁄ 共 1361字 ⁄ 字号 评论关闭

标题:自已实现服务器控件之Label控件

声明:本帖只是一个测试Demo,所以,不会写得太规范,也不会考虑到安全性.以方便为  主.所以,用得到的朋友在项目中使用的时候,还希望对其进行改进.

环境

开发工具:     VS.net 2003

数据库:       Sql Server 2000

作者:文刀无尽

日期:2006-02-20

读者要求:有一定的编程经验.

原理:也就是对HTML控件进行包装.


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

namespace Skyendless.MyControls
{
    
/// <summary>
    
/// WebCustomControl1 的摘要说明。
    
/// </summary>

    [DefaultProperty("Text"), 
        ToolboxData(
"<{0}:Label runat=server></{0}:Label>")]
    
public class Label : System.Web.UI.WebControls.WebControl
    
{
        
private string text;
    
        [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)
        
{
            
string outputHtml = "<div name = "+this.UniqueID+">"+this.Text+"</Div>";
            output.Write(outputHtml);
        }


    }

}

注:我以后会继续尝试对几个常用的服务器控件进行实现
这个只是一个简单的自定义控件,细心的朋友会发现,这个
控件在设计时是不能用鼠标拖动来控制大小的,至于怎么实
现,请看下自已实现服务器控件系列 之 设计时可用鼠标拖动大小的Label控件

抱歉!评论已关闭.