Use NumericUpDown to select days in month

1k Views Asked by At

Windows form application with a NumericUpDown and a DateTimePicker. Using the DateTimePicker to allow the user to select a time (21.20) I want to use the numericUpDown to allow the user to select a day.

How do I set the numericUpDown to only allow the user to select a valid day based on the number of days in the current month?

1

There are 1 best solutions below

1
On BEST ANSWER

Use the DateTime.DaysInMonth() function to set the Maximum() Property of your NumericUpDown() in the Load() Event of the Form:

    private void Form1_Load(object sender, EventArgs e)
    {
        numericUpDown1.Maximum = DateTime.DaysInMonth(DateTime.Today.Year, DateTime.Today.Month);
    }