空白的日期选择控件


    public class EmptyDateTimePicker : System.Windows.Forms.DateTimePicker
    {
        Label empt = new Label();
        //有过焦点
        public bool IsHasValue
        {
            get
            {
                return !empt.Visible;
            }
            set
            {
                empt.Visible = !value;
            }
        }

        public EmptyDateTimePicker()
        {
            this.DropDown += new EventHandler(EmptyDateTimePicker_DropDown);
            this.SizeChanged += new EventHandler(EmptyDateTimePicker_SizeChanged);
            this.Enter += new EventHandler(EmptyDateTimePicker_Enter);

            this.empt.BackColor = BackColor;
            this.empt.Location = new System.Drawing.Point(0, 0);
            this.empt.Name = "empt";
            this.empt.Size = new System.Drawing.Size(0, 0);
            this.Controls.Add(empt);

            empt.Click += new EventHandler(empt_Click);
        }

        //焦点
        void EmptyDateTimePicker_Enter(object sender, EventArgs e)
        {
            if (empt.Visible)
            {
                this.empt.Visible = false;
                this.Select();
            }
        }

        //大小变化 空白大小
        void EmptyDateTimePicker_SizeChanged(object sender, EventArgs e)
        {
            if (empt.Visible)
            {
                this.empt.Size = new System.Drawing.Size(this.Width - this.Height, this.Height);
            }
        }

        //点击空白
        void empt_Click(object sender, EventArgs e)
        {
            if (empt.Visible)
            {
                this.empt.Visible = false;
                this.Select();
            }
        }

        //下拉事件
        private void EmptyDateTimePicker_DropDown(object sender, EventArgs e)
        {
            if (empt.Visible)
            {
                this.empt.Visible = false;
            }
        }
    }

你可能感兴趣的:(空白的日期选择控件)