C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Usually: You can begin referencing the MonthControl in your program's C# code through the identifier monthControl1.
Date properties:
MinDate: 1/1/1753
MaxDate: 12/31/9998
Properties:
BackColor
ForeColor
TitleBackColor
TitleForeColor
TrailingForeColor
Next: We look at a code example that demonstrates setting the BoldedDates property.
C# program that uses MonthCalendar and BoldedDates
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// Set the BoldedDates property to a DateTime array.
// ... Use array initializer syntax to add tomorrow and two days after.
monthCalendar1.BoldedDates = new DateTime[]
{
DateTime.Today.AddDays(1),
DateTime.Today.AddDays(2),
DateTime.Today.AddDays(4)
};
}
}
}
Also: You can assign to all of these properties. This will change the currently selected square on the MonthCalendar.
C# program that uses SelectionRange
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// You can acquire the range using this property accessor.
SelectionRange range = monthCalendar1.SelectionRange;
DateTime start = range.Start;
DateTime end = range.End;
// Alternatively, you can use the SelectionStart and End properties.
DateTime startB = monthCalendar1.SelectionStart;
DateTime endB = monthCalendar1.SelectionEnd;
}
}
}
ShowTodayCircle: The ShowTodayCircle property adjusts the visibility of the box on the left of the "Today" display.
Here: The ShowWeekNumbers property was set to true. The numbers 14, 15, 16, 17, 18, and 19 are the numbers of the weeks in the year.
Note: When this event handler executes, you can detect the SelectionRange. You can also access the properties on the DateRangeEventArgs.
C# program that uses DateChanged
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
{
// The user changed the current selection.
// ... Bug him or her with an obnoxious message box.
// ... It will really help the world be a better place.
MessageBox.Show("DateChanged: " +
monthCalendar1.SelectionRange.ToString());
}
}
}
And: For programs where the calendar is important or key, this may not be sufficient. But in most cases this control is ideal.