Click here to Skip to main content
15,897,704 members
Articles / Programming Languages / C#

Advanced DateTimePicker

Rate me:
Please Sign up or sign in to vote.
4.23/5 (7 votes)
18 Apr 2013CPOL 28.3K   3.4K   16  
Extended DateTimePicker for Windows Form applications
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace DatePicker
{
    public class advancedDatePicker : System.Windows.Forms.DateTimePicker   
    {
        private PopupWindowHelper popupHelper;

        /// <summary>
        /// Color of the DatePicker header
        /// </summary>
        [Description("Color of the DatePicker header")]
        [Browsable(true), Category("DatePicker")]
        public Color HeaderColor
        {
            get;
            set;
        }


		public advancedDatePicker() : base()
		{
            popupHelper = new PopupWindowHelper();
            Button btn = new Button();
            btn.Dock = System.Windows.Forms.DockStyle.Right;
            btn.Image = Properties.Resources.datePicker;
    	    btn.Width = 28;
            this.Controls.Add(btn);
            btn.Click += btn_Click;

		}

        private void btn_Click(object sender, EventArgs e)
        {
            var btn = sender as Button; 
            Form f = FindForm();
            var popup = new frmDatePicker(HeaderColor);
            popup.cmb_Cal = this;
            popup.CurrentDate = Convert.ToDateTime(Value);
            Value = popup.CurrentDate;

            Point location = PointToScreen(new Point(btn.Left-Width + btn.Width , btn.Bottom));
            popupHelper.ShowPopup(f, popup, location);
        }

	}

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Other Other
.NET, Web developer
MSc in Computer Science

Comments and Discussions