1

如何在 c sharp .net 的窗口形式应用程序中设置 datatimepicker。当我关注该日期文本框时,会显示我的 datetimepicker 控件,然后单击该日期中的特定日期,然后在文本框中显示 myformatted 输出。我使用简单的 datetimepicker 控件。

我只在 c#.net 的窗口窗体应用程序中使用 datetimepicker 控件

4

4 回答 4

1

您可以使用ValueChangedEvent indateTimePicker轻松完成此操作。

private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
   textBox1.Text = YourFormatedMethod(dateTimePicker1.Text);
}

private string YourFormatedMethod(string selectedDate)
{
  // Your implementation
}
于 2013-10-15T13:27:55.073 回答
0

您可以使用数据绑定:

将其放在表单加载中:

//textBox1.DataBindings.Add("Text", dateTimePicker1, "Text");
//or...
Binding b = new Binding("Text", dateTimePicker1, "Value",true);
b.Format += new ConvertEventHandler(b_Format);
textBox1.DataBindings.Add(b);

然后是 b_Format 处理程序:

private void b_Format(object sender, ConvertEventArgs e)
{
    //some checking you might want to do...

    e.Value = //your formatting here.
}
于 2013-10-15T13:43:32.870 回答
0
 private void dateTimePickerBillDate_ValueChanged(object sender, EventArgs e)
        {
            DateTime pickdt = Convert.ToDateTime(dateTimePickerBillDate.Text);
            maskedtxtBillDate.Text = pickdt.ToString();
        }
于 2017-12-12T12:59:51.320 回答
0
      // date time picker event code
      private void dtpfromdate_ValueChanged(object sender, EventArgs e){
          dtpfromdate.Format = DateTimePickerFormat.Custom;

          //here we can select our desired format.
          dtpfromdate.CustomFormat = "dd-MM-yyyy";
          txtfromdate.Text = dtpfromdate.CustomFormat;

          //assign the datetime picker value to textbox.
          txtfromdate.Text = dtpfromdate.Value.ToString("dd-MM-yyyy");
      }
于 2015-09-08T12:34:15.210 回答