mylabel.cs

来自「Professional ASP.NET source code」· CS 代码 · 共 60 行

CS
60
字号
using System;
using System.Web;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.WebControls	;

namespace WroxControls 
{
   public class MyLabelStyle : Control
   {
      string _text;

      public string Text
      {
         get{ return _text; }
         set{ _text = value; }  
      }

      int _repeatCount = 1;
 
      public int RepeatCount
      {
         get { return _repeatCount; }
         set { _repeatCount = value; }
      }

		Style _style = new Style();
      public Style LabelStyle
      {
         get { return _style; }
      }
		
      public Color ForeColor
      {
         get { return _style.ForeColor; }
         set { _style.ForeColor = value; }
      }

      protected override void OnInit(EventArgs e)
      {
         if ( _text == null )
             _text = "Here is some default text";
      }

      protected override void Render(HtmlTextWriter writer) 
      { 
         int loop;
         for( loop=0; loop < _repeatCount; loop++ )
         {

				_style.AddAttributesToRender( writer );
            writer.RenderBeginTag("h1");
            writer.Write( _text );
            writer.RenderEndTag();
         }
      }

   }
};

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?