Job Name-4
Job Name-4
Objective:
This lab exercise demonstrates two C# programs utilizing Windows Forms applications. The first program
determines the numerical representation of a selected day from a combo box, while the second program
generates a list of numbers based on user input.
Description:
This program takes a selected day from a combo box and displays its corresponding number in the week
using a message box. If no selection is made or an invalid value is entered, the program prompts the user
accordingly.
Code Implementation:
private void button1_Click(object sender, EventArgs e)
{
if (dayListComboBox.SelectedItem == null)
{
MessageBox.Show("Please select a day from the combo box.", "Day Number of
the Week", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (day == "SAT")
{
MessageBox.Show("DAY-1", "Day Number of the week", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
else if (day == "SUN")
{
MessageBox.Show("DAY-2", "Day Number of the week", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
else if (day == "MON")
{
MessageBox.Show("DAY-3", "Day Number of the week", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
else if (day == "TUE")
{
MessageBox.Show("DAY-4", "Day Number of the week", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
else if (day == "WED")
{
MessageBox.Show("DAY-5", "Day Number of the week", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
else if (day == "THU")
{
MessageBox.Show("DAY-6", "Day Number of the week", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
else if (day == "FRI")
{
MessageBox.Show("DAY-7", "Day Number of the week", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Please select a valid day from the combo box.", "Day
Number of the Week", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
Output:
Description:
This program takes a user-entered number from a text box and generates a list of sequential numbers
from 1 to the entered number. The results are displayed in a list box. The program ensures that only
positive integers are accepted.
Code Implementation:
private void Addition_Click(object sender, EventArgs e)
{
int maxItemNumber;
bool parseNum = int.TryParse(numberTextBox.Text, out maxItemNumber);
if (maxItemNumber > 0 && parseNum)
{
for (int i = 1; i <= maxItemNumber; i++)
{
listItemBox.Items.Add(i.ToString());
}
}else if (!parseNum)
{
MessageBox.Show("Please enter number value.", "Message",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
MessageBox.Show("Please enter positive number.", "Message",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
Output:
Conclusion:
Both programs successfully implement Windows Forms features, user input validation, and message box
interactions. The first program demonstrates control selection handling, while the second program
illustrates iterative data population. These concepts are fundamental for building interactive applications
in C# using Visual Studio.