Home > Net >  How to Drop down the DateTimePicker Programmatically? - VB.NET
How to Drop down the DateTimePicker Programmatically? - VB.NET

Time:07-22

Wondering how I could drop down the calendar of DateTimePicker

So I have the below code/event when a TextBox clicked, instantiate a new a DataTimePicker programmatically and added to the Form.

Private Sub TextBox1_Click(sender As Object, e As EventArgs) Handles TextBox1.Click

        Dim dtm = New System.Windows.Forms.DateTimePicker()
        With dtm
            .Font = New System.Drawing.Font("Comic Sans MS", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            .Format = System.Windows.Forms.DateTimePickerFormat.Custom
            .Location = New System.Drawing.Point(153, 237)
            .Size = New System.Drawing.Size(173, 35)
        End With

        Me.GroupBox1.Controls.Add(dtm)
        dtm.Show()

    End Sub

The above shows the DateTimePicker.

How could I display the "Drop Down" calendar as soon as the DateTimePicker is shown

CodePudding user response:

If the calendar part is the only reason for the DateTimePicker then a MonthCalendar control would be more appropriate. There's no dropping down in that case, so you can just show the control when and where you want.

  • Related