'Common C#/C# GDI+ Study'에 해당되는 글 4건

  1. 2008.11.14 Button 테두리 변경
  2. 2008.06.09 UserControl #3 (TextBox #2)
  3. 2008.06.09 UserControl #3 (TextBox)
  4. 2008.06.09 UserControl 연습 #2
Common C#/C# GDI+ Study2008. 11. 14. 10:12
http://www.microsoft.com/korea/msdn/smartclient/community/wffaq/ctrl.aspx#Qca22q9ci
using System.Drawing;
using System.Windows.Forms;

public class ButtonWithCustomBorder : Button
{
  protected override void OnPaint( PaintEventArgs e )
  {
    base.OnPaint( e );
    
    Color borderColor = Color.Blue;
    int borderWidth = 1; 
    int borderStyle = ButtonBorderStyle.Solid;

    ControlPaint.DrawBorder(
      e.Graphics, e.ClipRectangle,
      borderColor, borderWidth, borderStyle,
      borderColor, borderWidth, borderStyle,
      borderColor, borderWidth, borderStyle, 
      borderColor, borderWidth, borderStyle ); 
  }
}

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

        // Event Method
        #region OnKeyUp
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        protected override void OnKeyUp(System.Windows.Forms.KeyEventArgs e)
        {
            // Label 형태의 스킨일 경우 입력 형식을 검사하지 않는다.
            if (!this.labelEnabled)
            {
                int startIndex = this.SelectionStart;
                if (startIndex > 0)
                {
                    string pattern = null;

                    // 정규식에 대한 패턴을 설정한다. 오류 문자열에 대한 패턴을 작성해야 된다.
                    switch (this.inputFormat)
                    {
                        case InputFormat.EnglishOnly:
                            if (this.spaceKeyEnabled)
                                pattern = @"[^ a-zA-Z0-9_-]+";
                            else
                                pattern = @"[^a-zA-Z0-9_-]+";
                            break;

                        case InputFormat.KoreanOnly:
                            if (this.spaceKeyEnabled)
                                pattern = @"[^ ㄱ-힣0-9_-]+";
                            else
                                pattern = @"[^ㄱ-힣0-9_-]+";
                            break;

                        case InputFormat.All:
                            if (!this.spaceKeyEnabled)
                                pattern = @"[ ]";
                            break;
                    }

                    if (pattern != null && Regex.IsMatch(this.Text, pattern))
                    {
                        this.Text = this.Text.Substring(0, startIndex - 1) + this.Text.Substring(startIndex);
                        this.Select(startIndex - 1, 0);
                    }
                }
            }

            base.OnKeyUp(e);
        }
        #endregion
        #region OnLeave
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLeave(EventArgs e)
        {
            if (this.trimEnabled) this.Text = this.Text.Trim();

            // 문자열 수 검사
            if (this.MaxStringLength > -1 && this.MaxStringLength < System.Text.Encoding.Default.GetBytes(this.Text).Length)
            {
                Core.Forms.MessageViewer.ShowDialog("항목이 " + this.MaxStringLength + " Byte를 초과하였습니다(영문 1 Byte, 한글 2 Byte).", System.Windows.Forms.MessageBoxIcon.Warning);

                this.Focus();
            }

            base.OnLeave(e);
        }
        #endregion

Posted by penguindori
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
Common C#/C# GDI+ Study2008. 6. 9. 16:09
using System;
using System.Collections.Generic;
using System.Text;

namespace ICS.Core.Controls
{
    #region IControlBase
    /// <summary>
    /// 컨트롤의 공통 기능을 정의한다.
    /// </summary>
    public interface IControlBase
    {
        /// <summary>
        /// 필수 입력 여부를 가져오거나 설정한다.
        /// </summary>
        bool Mandatory
        {
            get;
            set;
        }

        /// <summary>
        /// 입력할 수 있는 문자열의 최대 길이를 설정한다. 영문은 1Byte, 한글은 2Byte로 계산된다.
        /// </summary>
        int MaxStringLength
        {
            get;
            set;
        }
    }
    #endregion

    #region BindingType - 컨트롤 바인딩 방법 정의
    /// <summary>
    /// 컨트롤의 바인딩 방법을 정의합니다.
    /// </summary>
    public enum BindingType
    {
        /// <summary>
        /// 바인딩을 하지 않습니다.
        /// </summary>
        None,
        /// <summary>
        /// 컨트롤이 활성 상태가 되었을 경우 바인딩합니다.
        /// </summary>
        Enter,
        /// <summary>
        /// DropDown 이벤트 발생시 바인딩합니다.
        /// </summary>
        DropDown,
        /// <summary>
        /// 폼 로드시 바인딩합니다.
        /// </summary>
        FormLoad
    }
    #endregion
    #region InputFormat - 입력 형식 정의
    /// <summary>
    /// 입력 형식을 정의합니다.
    /// </summary>
    public enum InputFormat
    {
        /// <summary>
        /// 모든 입력값을 받습니다.
        /// </summary>
        All,
        /// <summary>
        /// 영문만 입력할 수 있습니다.
        /// </summary>
        EnglishOnly,
        /// <summary>
        /// 한글만 입력할 수 있습니다.
        /// </summary>
        KoreanOnly
    }
    #endregion
    #region PanelType - Panel Type 정의
    /// <summary>
    /// Display 형태를 정의합니다.
    /// </summary>
    public enum PanelType
    {
        /// <summary>
        /// 표시하지 않습니다.
        /// </summary>
        None,
        /// <summary>
        /// 기본 모양으로 설정합니다.
        /// </summary>
        Standard,
        /// <summary>
        /// 상세 정보 모양으로 설정합니다.
        /// </summary>
        Detail,
        /// <summary>
        /// 필수 정보 모양으로 설정합니다.
        /// </summary>
        Mandatory,
        /// <summary>
        /// 조회 조건 모양으로 설정합니다.
        /// </summary>
        Search
    }
    #endregion
    #region ListBoxType - List Box Type 정의
    /// <summary>
    /// Display 형태를 정의합니다.
    /// </summary>
    public enum ListBoxType
    {
        /// <summary>
        ///
        /// </summary>
        None,
        /// <summary>
        ///
        /// </summary>
        Standard,
        /// <summary>
        ///
        /// </summary>
        Logging
    }
    #endregion
    #region TabType - Tab Type 정의
    /// <summary>
    /// Tab Type을 정의합니다.
    /// </summary>
    public enum TabType
    {
        /// <summary>
        ///
        /// </summary>
        None,
        /// <summary>
        ///
        /// </summary>
        Standard,
        /// <summary>
        ///
        /// </summary>
        Detail
    }
    #endregion
    #region Skin Color - Main Menu Skin Color 정의
    /// <summary>
    /// Main Menu의 Skin Color를 정의합니다.
    /// </summary>
    public enum SkinColor
    {
        /// <summary>
        ///
        /// </summary>
        Whites,
        /// <summary>
        ///
        /// </summary>
        Blues,
        /// <summary>
        ///
        /// </summary>
        Reds,
        /// <summary>
        ///
        /// </summary>
        Greens
    }
    #endregion

Posted by penguindori