Click here to Skip to main content
12,560,765 members (53,303 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#
I am creating one windows application in C#.
In my one form there is one field of type date time.

I have created one text box and just side of that have created one date time picker control. but I want that DTP become display as icon and when i will click on that icon it should open date time picker option.

Please let me know how can i set the DTP property to display as icon.
Or if no property then i will use icon image but how can i invoke the date time picker on the click event of that image and also i want the user selected value of the DTP .
Posted 5-Jan-11 7:31am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

You're going to have to build your own control to do this. But, it's not that hard.

As an example, here's a simple user control that does what you want. I added a textbox and a picturebox to a user control. Then, I set the picturebox image to an image of a calendar.

Then, here's the code using a MonthCalendar control:

public partial class IconDateTimePicker : UserControl
    MonthCalendar myCal;
    public IconDateTimePicker()
        //set up myCal
        myCal = new MonthCalendar();
        myCal.Visible = false;
        //hook the events
        myCal.DateSelected += new DateRangeEventHandler(this.monthCalendar_DateSelected);
        myCal.Leave += new EventHandler(this.monthCalendar_Leave);
    //handle when the PictureBox is clicked
    private void pictureBox1_Click(object sender, EventArgs e)
        myCal.Visible = !myCal.Visible;
    //handle when the UserControl has been added to a form
    private void IconDateTimePicker_ParentChanged(object sender, EventArgs e)
        //add mycal to the parent
        //you could also use a floating form
        myCal.Left = (this.Left + this.pictureBox1.Right) - myCal.Width;
        myCal.Top = this.Bottom + 5;
    private void monthCalendar_DateSelected(object sender, DateRangeEventArgs e)
        this.textBox1.Text = ((MonthCalendar)sender).SelectionStart.ToShortDateString();
        myCal.Visible = false;
    private void monthCalendar_Leave(object sender, EventArgs e)
        myCal.Visible = false;

This is very basic and you would want to add other things to it, such as minDate, maxDate, etc...

But you should get the idea of a simple way to do this.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If I understand you correctly, you can allways toggle the visiblility of the icon and the datetime picker using their respective .Visible property.

Espen Harlinn
Rahul Dhoble 5-Jan-11 14:14pm
The form format is like this

Member's Birth Date : <text box=""> <date time="" picker="">

Here i have locked the textbox . and user must use DTP to change the value.

But when i have used dtp . It shown as a small combo box , but i want that DTP shown as small calender icon.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.161026.1 | Last Updated 5 Jan 2011
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100