简体   繁体   中英

How to set date in Winforms Datetimepicker

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM