当用户按下按钮时(无需将控件添加到窗体),如何显示DateTimePicker对话框)

Jar*_*red 1 vb.net datetimepicker

我试图这样做,当用户按下一个按钮时,会显示一个DateTimePicker对话框,我甚至想得到他们选择的结果日期.这是我到目前为止所拥有的:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim Dis As System.Windows.Forms.DateTimePicker = New System.Windows.Forms.DateTimePicker()

    ' Set the MinDate and MaxDate.
    Dis.MinDate = New DateTime(1985, 6, 20)
    Dis.MaxDate = DateTime.Today

    ' Set the CustomFormat string.
    Dis.CustomFormat = "MMMM dd, yyyy - dddd"
    Dis.Format = Windows.Forms.DateTimePickerFormat.Custom

    ' Show the CheckBox and display the control as an up-down control.
    Dis.ShowCheckBox = True
    Dis.ShowUpDown = True

    Dis.Show()

End Sub
Run Code Online (Sandbox Code Playgroud)

但是当我按下按钮并运行代码时,没有任何内容显示出来.我认为应该有一种简单地以编程方式显示此对话框的方法.有人可以帮我吗?:-)

仅供参考,如果有任何帮助,我在VB 2010中对此进行编码?: - \

GST*_*STD 5

在vb.net中,a DateTimePicker不是像对话框OpenFileDialog, SaveFileDialog, PrintDialog或其他类似对话框那样的对话框.

尽管它的"弹出"外观DateTimePicker是一个控制对象,因此它必须放在(添加到)窗体或窗口之后才能显示和使用.