Click here to Skip to main content
Licence CPOL
First Posted 11 Apr 2007
Views 37,359
Downloads 733
Bookmarked 16 times

Composite Date & Time Control

By | 11 Apr 2007 | Article
A control showing both date and time

Screenshot - CompositeDateTime_pic.jpg

Introduction

This control displays the combined date and time, with calendar dropdown and updown arrows. It is basically two DatePicker controls merged using a SplitContainer. The splitter bar can be adjusted to give more room to either side.

This is my first attempt at such a control, so if there is another way, I'm open to suggestions.

Background

The DatePicker control can display only date or time values. I currently use a combined date/time control in our MFC apps (BCGDateTime). When I moved to VS 2005, I couldn't find one written for .NET, so I tackled this.

Adding the control

Use Add Reference to add a reference to the DateAndTimeControls assembly in your project.

Add the control to the toolbox by right-clicking in a category and using Choose Items.

Screenshot - choose_item.jpg

Drag the control onto the form. The properties panel shows the new properties and events:

  • DateTimeValue - the default property of the control.
  • DateValue - just the date value of the control
  • TimeValue - just the time value of the control>
  • MinDate - the minimum date/time value for the control
  • MaxDate - the maximum date/time value for the control
  • DateFormat - the enumerated datepicker format value (ie long)
  • DateCustom - the custom format mask (ie dd-MMM-yyyy)
  • TimeFormat - the enumerated DatePicker format value (ie time)
  • TimeCustom - the custom format mask (ie hh:mi tt)
  • ValueChanged - the default event for the control. fired whenever the value is changed.

Using the control

To get a value from the control:

dim dt as Date
dt = DateTimeControl1.DateTimeValue
tTextbox1.Text = dt.ToString("dd-mmm-yyyy hh:mi tt")

To put a value in the control:

DateTimeControl1.DateTimeValue = Date.Now

or

Date.TryParse(TextBox1.Text, DateTimeControl1.DateTimeValue)

The constructor will give an error if the date is outside the MinDate-MaxDate range.

To clear the control:

DateTimeControl1.DateTimeValue = new Date(0L)

The date can also be cleared by typing <Backspace> in the control.

Points of Interest

Thanks to this project, I learned how to expose new class events to the outside world.

License

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

About the Author

Richard Jones

Web Developer

Canada Canada

Member

I have been developing applications at City of Moncton since 1992. My focus has been on C/C++ along with Oracle and SQL/Plus.
 
I've been tainted with Oracle Developer, and Palm development. ick.
 
I am actively developing in .NET 2008.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionGood work Pinmemberpc180016:30 29 Nov '11  
GeneralMy vote of 1 PinmemberMember 824475123:45 18 Sep '11  
GeneralThank you! Pinmembera.pranav2:29 19 Apr '11  
QuestionHow to Set DateTimePicker value to Spaces [modified] Pinmembertreesprite15:56 21 Nov '10  
GeneralCant use in Web Application Pinmembersatejprabhu19:34 18 Oct '07  
GeneralRe: Cant use in Web Application [links are flipped] PinmemberRichard Jones2:11 19 Oct '07  
GeneralAnd Thanks from me too PinmemberHRybko20:56 20 Jul '07  
GeneralThanks Pinmemberlex-it.co.uk3:58 2 Jul '07  
GeneralRe: Thanks PinmemberRichard Jones1:33 3 Jul '07  
Generalthanks Pinmemberraj3482:47 24 Apr '07  
GeneralNice. PinmemberPete O'Hanlon4:36 13 Apr '07  
GeneralRe: Nice. PinmemberRichard Jones6:26 13 Apr '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 11 Apr 2007
Article Copyright 2007 by Richard Jones
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid