DotNetWebTutor.com                                                    Link to Us

Date Controls

  1. Datetimepicker control
  2. Monthcalendar control

Datetimepicker
Basically a textbox with a month calendar control hooked to it
Takes up a small amount of space
Value property gives you the selected date

Configure control to current date:
Datetimepicker1.value=datetime.now

Configure a new date:
Datetimepicker1.value=new dateTime(2007,01,22)

Monthcalendar control
A graphical calendar display
Can pick a range of dates
You can set a minimum and maximum number of dates
You can programmatically select dates
Example:
MonthCalendar1.SelectionStart=New DateTime(2008,01,01)
MonthCalendar1.SelectionEnd=New DateTime(2008,01,15)

This control does not work well selecting multiple dates using XP Styles

Properties
Showtoday-set to true displays todays date at bottom of calendar
Showtodaycircle- if true circled today in red
Maxdate,mindate
Text property – can enter date
Auto checks to see if it’s a date and highlights the specified date

Events:
DateChanged event fires when selected date changes

DateSelected event fires only when the user actually CLICKS on a date with the mouse

visual basic datepicker control
DatePicker Example

  • Start a new project
  • Add label, datetimepicker, button and monthcalendar to form

Goal:select dates from datetimepicker and display then in bold in monthcalendar control

  • Rename the controls
  • Select monthCalendar and click lightning bolt to get to the events
  • Select dateSelected event and double-click

 

When this fires it passes a daterangeeventarts object called e
It has 2 properties

  1. Start
  2. End

The start holds a date value
Tolongdatestring()
CONVERTS A DATE TO A STRING

  • Add this code

Datetimepicker1.text=e.start.tolongdatestring()

Monthcalendar control has a boldeddates property

It is an array of datetime objects
You need to add an element to it

  • Double-click add button

 

Dim boldDates() as system.datetime
boldDates=calendar.boldeddates
redim preserver bolddates(calendar.boldeddates.length+1)
boldDates(calendar.boldedDates.length+1)- _
system.datetime.parse(datetimepicker1.text)
calendar.boldeddates-bolddates

 

date controls