Let us look at a simple C# Windows Forms MonthCalendar example.
Example 1: MonthCalendar
This example will comprise the following files:
MonthCalendar.cs
Step 1: Create Project
- The first step is to create a C# Project.
- Go to
FILE-->New-->Project
to create a new project.
Step 2: Write Code
Write Code as follows:
*(a). MonthCalendar.cs
Create a file named MonthCalendar.cs
Here is the full code
using System;
using System.Windows.Forms;
namespace Examples {
class MainForm : Form {
public static void Main() {
Application.EnableVisualStyles();
Application.Run(new MainForm());
}
public MainForm() {
Text = "MonthCalendar example";
monthCalendar1.Parent = this;
monthCalendar1.MinDate = new DateTime(1971, 1, 5);
monthCalendar1.MaxDate = new DateTime(2071, 1, 5);
monthCalendar1.SelectionRange = new SelectionRange(DateTime.Now - TimeSpan.FromDays(1), DateTime.Now + TimeSpan.FromDays(1));
monthCalendar1.Location = new System.Drawing.Point(10, 10);
monthCalendar1.DateSelected += delegate {
MessageBox.Show(string.Format("range = [{0}; {1}]", monthCalendar1.SelectionRange.Start.ToShortDateString(), monthCalendar1.SelectionRange.End.ToShortDateString()), "Date selected :");
};
}
private MonthCalendar monthCalendar1 = new MonthCalendar();
}
}
Run
Simply copy the source code into your C# Project,Build and Run. Alternatively download the code using the links provided below, then open the .csproj
project, build and run.
Reference
Download the code using the below links:
Number | Link |
---|---|
1. | Download Example |
2. | Follow code author |