populating textbox using datetime picker

I am using VB 2005 for developing a winform application

I want to display a datetime picker ( or a calendar) to choose date when a user click on the textbox
very similar to
www.expedia.com

on the textbox click event I am using the following code to display datetime picker's calendar GUI

PrivateSub TextBox1_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles TextBox1.Click

DateTimePicker1.Select()

SendKeys.Send("%{DOWN}")

EndSub

is there any easy to remove the combobox out of the Datetime picker? so when a user click on the textbox
datetime picker's calendar Gui will displayed and a user selects a date that populates the textbox

[1791 byte] By [c_shah] at [2007-12-22]
# 1
On the textbox's click event bring up a modal dialog box that has the control you want. When focus is removed update the textbox appropriatly.
OmegaMan at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2

Hi,

is there some reason why you don't want to use DateTimePicker itself for choosing dates?

Here's also something you can start with:

You have a text box on your form. Put a MonthCalendar on the form and set its Visible property to False.

Write the following handlers:

Private Sub TextBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.Click
MonthCalendar1.Location =
New Point(TextBox1.Left, TextBox1.Bottom)
MonthCalendar1.Show()
End Sub

The first one will open the MonthCalendar below the text box when text box gets clicked on.

Private Sub MonthCalendar1_DateSelected(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendar1.DateSelected
TextBox1.Text = e.Start.ToShortDateString()
MonthCalendar1.Hide()
End Sub

The second one will enter selected date in the text box and hide the calendar, when a date has been selected.

Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = ChrW(Keys.Escape) AndAlso MonthCalendar1.Visible Then
MonthCalendar1.Hide()
e.Handled =
True
End If
End Sub

The last one will just hide the calendar if escaped was pressed when text box has focus.

Andrej

AndrejTozon at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3
Thanks!
c_shah at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 4
So other users can know which one helped you, mark the post(s) that you found helpful as answers.
OmegaMan at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 5

How can I use this code on more then one TextBox?

thanks Frank.

Frank104 at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...