Set B
19) Design an application for selecting a single day in the calendar
control.
Aim:
To design an application for selecting a single day in the calendar
control.
Algorithm:
Step 1: Start the program and initialize the form.
Step 2: Set the calendar control (monthCalendar1) to only allow
selecting one day at a time by setting MaxSelectionCount to 1.
Step 3: Set the label (label1) text to prompt the user to select a date,
e.g., "Select a date".
Step 4: Attach an event handler to the calendar's DateChanged event
so that when the user changes the date selection, the program reacts.
Step 5: When the user selects a date on the calendar:
o Capture the selected date (e.Start).
o Update the label text to show the selected date in a short date
format, e.g., "Selected Date: 7/7/2025".
Step 6: The form is displayed with the calendar and label showing
current state.
Step 7: Stop the program.
C# code:
using System;
using System.Windows.Forms;
namespace singledayselectorapp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// Limit calendar selection to a single day
monthCalendar1.MaxSelectionCount = 1;
// Set initial label text
label1.Text = "Select a date";
// Attach event handler for date changes
monthCalendar1.DateChanged += MonthCalendar1_DateChanged;
}
private void MonthCalendar1_DateChanged(object sender,
DateRangeEventArgs e)
{
// Update the label with the selected date
label1.Text = "Selected Date: " + e.Start.ToShortDateString();
}
private void Form1_Load(object sender, EventArgs e)
{
private void monthCalendar_Click(object sender, EventArgs e)
{
private void monthCalendar1_DateChanged_1(object sender,
DateRangeEventArgs e)
{
}
}
}
OUTPUT: