zoukankan      html  css  js  c++  java
  • 自定义控件的 Enum类和Color类 属性的公开设定


    我们知道 常规状态下
    自定义控件经常使用String,Boolean型的属性
    这些属性公开后 在使用时 就可以看到可输入的文本框
    及有true和false供选择的下拉列表

    可是我们有时还要用到 更多内容的下拉列表 或 颜色选择框
    那么 下面就是
    自定义控件的 Enum类和Color类 属性的公开设定 的示例
    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.ComponentModel;

    namespace WebControlLibrary3
    {
     /// <summary>
     /// WebCustomControl1 的摘要描述。
     /// </summary>
     [DefaultProperty("Text"),
      ToolboxData("<{0}:WebCustomControl1 runat=server></{0}:WebCustomControl1>")]
     public class WebCustomControl1 : System.Web.UI.WebControls.WebControl
     {
      private string _text;
      private Button _button;
      private System.Drawing.Color _color;


      [Bindable(true),
       Category("Appearance"),
       DefaultValue("default_text"),
      Description("文本属性,显示在属性样下边提示部分")]
      public string Text
      {
       get
       {
        return _text;
       }

       set
       {
        _text = value;
       }
      }

      // 枚举
      public enum TextStyle
      {
       Normal,
       Italic,
       Bold,  
      }

         private TextStyle _textStyle;
      public TextStyle textStyle
      {
       get
       {
       return _textStyle;
       }
       set
       {
       _textStyle = value;
       }
      }
            // 系统颜色对话框

      [Bindable(true),
      Category("Appearance"),
      DefaultValue("Red"),
      Description("按钮背景颜色")]
      public System.Drawing.Color ButtonColor
      {
       get
       {
                   return _color;

       }
       set
       {
          _color = value;
       }
      }
           

      /// <summary>
      /// 呈现这个控制项到 output 参数所指定的物件。
      /// </summary>
      /// <param name="output"> 指定要输出的 HTML 写入器 (HTMLTextWriter)</param>
      protected override void Render(HtmlTextWriter output)
      {
       string StartStyle = null;
       string EndStyle = null;
       switch(this._textStyle)
       {
        case TextStyle.Normal:
         StartStyle="";
                        EndStyle="";
         break;
        case TextStyle.Italic:
         StartStyle="<I>";
         EndStyle="</I>";
         break;
       
        case TextStyle.Bold:
         StartStyle="<B>";
         EndStyle="</B>";
         break;   
       
       }   
       output.Write(StartStyle+Text+EndStyle);
       _button = new Button();
       _button.Text = "测试Color按钮";
       _button.BackColor = this._color;
       _button.RenderControl(output);
      }
     }
    }

  • 相关阅读:
    [转]DllMain中不当操作导致死锁问题的分析——DllMain中要谨慎写代码(完结篇)
    【机器学习】深入理解人工神经网络结构
    【机器学习】初识人工神经网络
    【机器学习】通过正则化解决过拟合问题
    【机器学习】逻辑回归
    【机器学习】用Octave实现一元线性回归的梯度下降算法
    【机器学习】对梯度下降算法的进一步理解
    【机器学习】从分类问题区别机器学习类型 与 初步介绍无监督学习算法 PAC
    【机器学习】感知机学习算法(PLA)
    【机器学习】1 监督学习应用与梯度下降
  • 原文地址:https://www.cnblogs.com/freeliver54/p/591986.html
Copyright © 2011-2022 走看看