PTR01
PTR01

Reputation: 83

Setting Minimum Date for Date Time Picker for Windows Forms C#

I'm currently working on a To-Do list Windows Forms application in C# which features a date time Picker, through some research I was able to find that I am able to set the MinValue property of the date time picker within the Designer Tab of the form.

The plan was to set the minimum date value for the date time picker through the following code:

    this.startDatePicker.MinDate = System.DateTime.Now;
    this.startDatePicker.Value = System.DateTime.Now;

This isn't an issue, this code is fine and it works. It successfully sets the minimum value for the date time picker to today, essentially preventing the user from choosing a date before this date.

HOWEVER, my issue is that for some reason the Designer Tab decides to reset this and automatically remove this code.

I was just wondering if there was a way I could prevent the Designer Tab from changing the minimum value for the date time picker?

Upvotes: 2

Views: 3691

Answers (1)

Roman Starkov
Roman Starkov

Reputation: 61540

Are you modifying the .Designer.cs file? It's autogenerated and all your changes will be lost. You're not supposed to edit it manually.

Just move those lines into the form constructor for the same effect, right after the call to InitializeComponent().

Upvotes: 6

Related Questions