Muokkaa

Jaa


DateTimePicker.Text is empty string

The Text property of the DateTimePicker control is now set to the empty string until a handle to the control is created.

Version introduced

.NET 8

Previous behavior

Previously, the DateTimePicker.Text property was available as soon as the DateTimePicker was constructed.

New behavior

Starting in .NET 8, the DateTimePicker.Text property is the empty string until a handle is created. Once the handle is created, Text is set to the date that's currently displayed in the control.

Change category

This change is a behavioral change.

Reason for change

This change was introduced so that what the narrator (screen reader) announces matches the displayed text.

If your code is affected by this change, access the Text property later on, as shown in the following code snippet.

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        Shown += DateTimePicker_Shown;
    }

    private void DateTimePicker_Shown(object sender, EventArgs e)
    {
        string date = this.dateTimePicker1.Text;
    }
}

Affected APIs