VB.net Programmably drop down the DateTimePicker

2020-05-08 17:38发布

Hey all i have this code here:

Call SendMessage(dtPicker.Handle, CB_SHOWDROPDOWN, True, 0&)

That works fine on comboboxes but doesn't seem to work when it comes to the DateTimePicker box.

What could be the problem?

Thanks!

David

1条回答
乱世女痞
2楼-- · 2020-05-08 17:56

No, that's for a ComboBox. The native DTP control is quite noddy. It supports the DTM_CLOSEMONTHCAL message to close the calendar but doesn't have a corresponding message to open it. You'll have to do something ugly like faking mouse or keyboard input. The latter is probably best:

Private Sub ShowMonthCalendar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShowMonthCalendar.Click
    DateTimePicker1.Focus()
    SendKeys.Send("{F4}")
End Sub
查看更多
登录 后发表回答