Common C#/C# GDI+ Study2008. 6. 9. 16:16

using System;
using System.ComponentModel;
using System.Text.RegularExpressions;

namespace ICS.Core.Controls
{
    /// <summary>
    /// Edit Box
    /// </summary>
    public partial class EditBox : System.Windows.Forms.TextBox, IControlBase
    {
        #region Constructor
        /// <summary>
        /// 기본 생성자입니다.
        /// </summary>
        public EditBox()
        {
            InitializeComponent();
        }
        #endregion

        // User Property
        #region Mandatory
        bool mandatory = false;
        /// <summary>
        /// 필수 입력 항목인지를 가져오거나 설정한다.
        /// </summary>
        [Category("ETC"), DefaultValue(false), Description("필수 입력 여부를 가져오거나 설정한다.")]
        public bool Mandatory
        {
            get { return mandatory; }
            set
            {
                this.mandatory = value;

                if (value)
                {
                    this.BackColor = System.Drawing.Color.Cornsilk;
                }
                else
                {
                    if (this.labelEnabled) this.BackColor = System.Drawing.Color.WhiteSmoke;
                    else this.BackColor = System.Drawing.Color.White;
                }
            }
        }
        #endregion
        #region LabelEnabled
        bool labelEnabled = false;
        /// <summary>
        /// Label과 같이 수정할 수 없는 컨트롤로의 설정 여부를 나타낸다.
        /// </summary>
        [Category("ETC"), DefaultValue(false), Description("Label과 같이 수정할 수 없는 컨트롤로의 설정 여부를 나타낸다.")]
        public bool LabelEnabled
        {
            get { return this.labelEnabled; }
            set
            {
                this.labelEnabled = value;

                if (value)
                {
                    this.ReadOnly = true;
                    if (this.mandatory) this.BackColor = System.Drawing.Color.Cornsilk;
                    else this.BackColor = System.Drawing.Color.WhiteSmoke;
                    this.ForeColor = System.Drawing.Color.FromArgb(100, 100, 100);
                    this.TabStop = false;
                }
                else
                {
                    this.ReadOnly = false;
                    if (this.mandatory) this.BackColor = System.Drawing.Color.Cornsilk;
                    else this.BackColor = System.Drawing.Color.White;
                    this.ForeColor = System.Drawing.Color.Black;
                    this.TabStop = true;
                }
            }
        }
        #endregion
        #region TrimEnabled
        bool trimEnabled = true;
        /// <summary>
        /// Trim 기능을 사용할지 여부를 가져오거나 설정한다.
        /// </summary>
        [Category("ETC"), DefaultValue(true), Description("Trim 기능을 사용할지 여부를 가져오거나 설정한다.")]
        public bool TrimEnabled
        {
            get { return trimEnabled; }
            set { trimEnabled = value; }
        }
        #endregion
        #region MaxStringLength
        int maxStringLength = 40;
        /// <summary>
        /// 입력할 수 있는 문자열의 최대 길이를 설정한다. 영문은 1Byte, 한글은 2Byte로 계산된다.
        /// -1로 설정하면 문자열 길이를 검사하지 않는다는 의미이다.
        /// </summary>
        [Category("ETC"), DefaultValue(40), Description("입력할 수 있는 문자열의 최대 길이를 설정한다. 영문은 1Byte, 한글은 2Byte로 계산된다. -1로 설정하면 문자열 길이를 검사하지 않는다는 의미이다.")]
        public int MaxStringLength
        {
            get { return maxStringLength; }
            set { maxStringLength = value; }
        }
        #endregion
        #region InputFormat
        InputFormat inputFormat = InputFormat.All;
        /// <summary>
        /// 입력 형식을 가져오거나 설정한다. 이 설정값에 따라 IME 모드가 변경된다.
        /// </summary>
        [Category("ETC"), DefaultValue(InputFormat.All), Description("입력 형식을 가져오거나 설정한다. 이 설정값에 따라 IME 모드가 변경된다.")]
        public InputFormat InputFormat
        {
            get { return inputFormat; }
            set
            {
                inputFormat = value;

                switch (value)
                {
                    case InputFormat.EnglishOnly:
                        this.ImeMode = System.Windows.Forms.ImeMode.Alpha;
                        break;

                    case InputFormat.KoreanOnly:
                        this.ImeMode = System.Windows.Forms.ImeMode.Hangul;
                        break;
                }
            }
        }
        #endregion
        #region SpaceKeyEnabled
        bool spaceKeyEnabled = false;
        /// <summary>
        /// 공백(' ')키를 사용할 수 있는지 여부를 가져오거나 설정한다.
        /// </summary>
        [Category("ETC"), DefaultValue(false), Description("공백(' ')키를 사용할 수 있는지 여부를 가져오거나 설정한다.")]
        public bool SpaceKeyEnabled
        {
            get { return spaceKeyEnabled; }
            set { spaceKeyEnabled = value; }
        }
        #endregion
<-----추가 부분----->
   }
}

Posted by penguindori