classproperties.cs

来自「这是《ASP.NET编程实作教程》一书中的源文件 如果有此书的朋友不防下载过来参」· CS 代码 · 共 60 行

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

namespace myControl {
	
    //类myFontStyle用于保存字体的信息
    public class myFontStyle {
 
    //私有变量_fontSzie,字体的大小
    private int     _fontSize;
    //私有变量_fontColor,字体的颜色
    private String  _fontColor;

    //类的构造函数
    public myFontStyle(int size, String color) {
         this.fontSize = size;
         this.fontColor = color;
    }
    
    //fontColor属性
    public String fontColor {
         get {
              return _fontColor;
          }
         set {
              _fontColor = value;
          }
     }
     
     //fontSize属性
     public int fontSize {
          get {
              return _fontSize;
          }
          set {
              _fontSize = value;
          }
        }    
    }
    
    //类ClassProperties定义控件
    public class ClassProperties : Control {
       
       //私有变量_myFont,是myFontStyle的实例
       private myFontStyle _myFont  = new myFontStyle(4, "blue");
       
       //属性myFont,用于控制字体显示效果
       public myFontStyle myFont {
           get {
              return _myFont;
           }
       }

       protected override void Render(HtmlTextWriter output) {
          output.Write("<font size="+ myFont.fontSize);
          output.Write(" color='" + myFont.fontColor +"'>"+"HelloWorld"+"</font>");
       }
    }    
}

⌨️ 快捷键说明

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