Classroom Exercises on Visual Studio
Classroom Exercises on Visual Studio
Objective:
Learn to create a simple Windows Forms Application using Visual Studio. This program will demonstrate
the use of common controls like ListBox, CheckBox, Button, and TextBox.
o Click Create.
o ListBox
▪ Name it listBoxItems.
o CheckBoxes
▪ Drag and drop three CheckBox controls onto the form, aligned vertically.
o Button
▪ Name it buttonAddItems.
o TextBox
▪ Name it textBoxInput.
▪ Set its PlaceholderText property (or Text to a default value like "Enter text").
o Label
1
▪ Name it labelMessage.
csharp
Copy code
labelMessage.Text = "";
// Add the text from the TextBox to the ListBox if not empty
if (!string.IsNullOrEmpty(inputText))
listBoxItems.Items.Add(inputText);
else
// Check which CheckBoxes are selected and add their text to the ListBox
if (checkBoxOption1.Checked)
listBoxItems.Items.Add(checkBoxOption1.Text);
2
if (checkBoxOption2.Checked)
listBoxItems.Items.Add(checkBoxOption2.Text);
if (checkBoxOption3.Checked)
listBoxItems.Items.Add(checkBoxOption3.Text);
textBoxInput.Clear();
o Press F5 or click on the Start button in Visual Studio to build and run the application.
o Enter text in the TextBox and click the Add Items button. The entered text should appear
in the ListBox.
o Select one or more CheckBox options and click the button again. The selected options
should also appear in the ListBox.
• Add a Clear Button: Include a button to clear all items in the ListBox.
• Enable Selection: Allow the user to remove selected items from the ListBox using another
button.
• Customize Appearance: Change properties like colors, fonts, and sizes for better aesthetics.
Outcome:
Students will create a functional Windows Forms application demonstrating the usage of ListBox,
CheckBox, Button, and TextBox, enhancing their understanding of basic controls and event handling in
Visual Studio.
3
Classroom Exercise 2: Windows Forms Application with ComboBox,
RadioButton, and ProgressBar
Objective:
Learn to create a Windows Forms Application using Visual Studio that incorporates the use of
ComboBox, RadioButton, and ProgressBar. The program will demonstrate how these controls can
interact dynamically.
o Click Create.
o ComboBox
▪ Name it comboBoxColors.
▪ Set its DropDownStyle property to DropDownList (so users can only select
predefined options).
o RadioButtons
▪ Add three RadioButton controls and arrange them vertically below the
ComboBox.
▪ Group them by placing them inside a GroupBox control for logical grouping
(optional).
o ProgressBar
▪ Drag and drop a ProgressBar onto the form, below the RadioButton group.
▪ Name it progressBarTask.
4
o Button
▪ Name it buttonStart.
o Label
▪ Name it labelStatus.
csharp
Copy code
comboBoxColors.Items.Add("Red");
comboBoxColors.Items.Add("Green");
comboBoxColors.Items.Add("Blue");
csharp
Copy code
if (radioButtonSmall.Checked)
5
progressBarTask.Value = 25;
else if (radioButtonMedium.Checked)
progressBarTask.Value = 50;
else if (radioButtonLarge.Checked)
progressBarTask.Value = 100;
else
return;
if (comboBoxColors.SelectedItem != null)
switch (selectedColor)
case "Red":
progressBarTask.ForeColor = System.Drawing.Color.Red;
break;
case "Green":
6
progressBarTask.ForeColor = System.Drawing.Color.Green;
break;
case "Blue":
progressBarTask.ForeColor = System.Drawing.Color.Blue;
break;
else
o Click the Start Task button to see the ProgressBar update dynamically based on your
selections.
• Add a Reset Button: Include a button to reset the ProgressBar and selections.
• Dynamic ComboBox Items: Allow users to add new colors to the ComboBox using a TextBox and
Button.
• Advanced ProgressBar Behavior: Implement a timer to animate the ProgressBar filling gradually.
Outcome:
Students will gain experience with ComboBox, RadioButton, and ProgressBar controls, along with event
handling and conditional logic in Visual Studio. This exercise also introduces dynamic UI updates based
on user interaction.