How to set date in Winforms Datetimepicker

2.6k Views Asked by At

I have Winform in which i have date time picker so I need to know how can I set default date value to 01 in datetime picker, and user cant change the date. How ever he/she can change the month or the year, but the default date remains the same ie; 01.

1

There are 1 best solutions below

0
Gustav Klimt On BEST ANSWER

pick some event that you will use. I did build string, but you can rewritte better code and much simpler. This is just an example for you to understand.

        int year = Convert.ToDateTime(dateTimePicker1.Text).Year;
        int month = Convert.ToDateTime(dateTimePicker1.Text).Month;
        dateTimePicker1.Text = DateTime.ParseExact("01." + month.ToString() + "." + year.ToString(), "dd.mm.yyyy",System.Globalization.CultureInfo.InvariantCulture).ToString();

hope it helps