■ DateEdit 클래스 : CloseUp 이벤트를 사용해 사용자 입력 제한하기

------------------------------------------------------------------------------------------------------------------------


TestProject.zip


MainForm.cs

 

 

using System;

 

using DevExpress.XtraEditors;

using DevExpress.XtraEditors.Controls;

 

namespace TestProject

{

    /// <summary>

    /// 메인 폼

    /// </summary>

    public partial class MainForm : XtraForm

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 생성자 - MainForm()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public MainForm()

        {

            InitializeComponent();

 

            this.dateEdit.Properties.TextEditStyle = TextEditStyles.DisableTextEditor;

 

            this.dateEdit.CloseUp += dateEdit_CloseUp;

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Private

 

        #region 날짜 에디터 팝업 닫는 경우 처리하기 - dateEdit_CloseUp(sender, e)

 

        /// <summary>

        /// 날짜 에디터 팝업 닫는 경우 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void dateEdit_CloseUp(object sender, CloseUpEventArgs e)

        {

            DateTime dateTimeSelected = (DateTime)e.Value;

 

            int currentYear = DateTime.Today.Year;

 

            if(dateTimeSelected.Year < currentYear)

            {

                e.Value = new DateTime(currentYear, 1, 1);

            }

            else

            {

                if(dateTimeSelected.Year > currentYear)

                {

                    e.Value = new DateTime(currentYear, 12, 31);

                }

            }

        }

 

        #endregion

    }

}

 

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요