0

Is it possible to display a datetimepicker when a TextBox(MetroTextBox) is clicked? Well what I am trying to do is when I click the TextBox it will display a datetimepicker above the Textbox or below the textbox then If I select a certain date it will display the date in the textbox.

I have this as a basis, but I cant make it work.

Show DateTimePicker in Textbox

Cremlic
  • 88
  • 9

1 Answers1

0

I've met my desired result by using MonthCalendar instead of DTP.

here's the code for future reference of other people in case they want a same output. Thanks, Peace!...

Private Sub NotificationV2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    MonthCalendar1.BringToFront()
    MonthCalendar1.Location = New Point(265, 160)
    MonthCalendar1.Visible = False
End Sub

Private Sub MetroTextBox8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MetroTextBox8.Click
    MonthCalendar1.Visible = Not MonthCalendar1.Visible
End Sub

Private Sub MonthCalendar1_DateSelected(ByVal sender As Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendar1.DateSelected
    MonthCalendar1.Visible = False
    MetroTextBox8.Text = e.Start.ToShortDateString
End Sub
Cremlic
  • 88
  • 9
  • I would suggest that rather than show the calendar on the textbox.click event, create a context menu and link it to the textbox using the ContextMenuStrip property in the Visual Studio Properties window. If the user wants to reposition the cursor using the mouse left click (which is a more intuitive use) all they will do using our code is open the calendar. Frustrating maybe. Sorry this advice is for a Winforms app. It may be rather different if you're not using winforms. :) – David Wilson Apr 25 '18 at 01:12