[go: up one dir, main page]

0% found this document useful (0 votes)
33 views7 pages

Using Controls On Windows Form Lab 2

The document discusses creating employee and student registration forms in Windows Forms using various controls like text boxes, check boxes, radio buttons, date/time pickers, list boxes, and combo boxes. It provides steps to add controls to a form, set their properties, add items to list/combo boxes, and code behind to retrieve values and display outputs. The objective is to explore how different controls work in Windows Forms and create simple registration forms using these controls.

Uploaded by

Raza khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views7 pages

Using Controls On Windows Form Lab 2

The document discusses creating employee and student registration forms in Windows Forms using various controls like text boxes, check boxes, radio buttons, date/time pickers, list boxes, and combo boxes. It provides steps to add controls to a form, set their properties, add items to list/combo boxes, and code behind to retrieve values and display outputs. The objective is to explore how different controls work in Windows Forms and create simple registration forms using these controls.

Uploaded by

Raza khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Using Controls on Windows Form Lab 2

Objective: To explore the different controls like CheckBox, RadioButton with a GroupBox,
NumericUpDown, DateTimePicker, ComboBox, and ListBox on Windows Forms.

Task: Create a Employee registration form using windows forms.

1. Go to File-> New -> Project-> Visual C#->Windows Form application-> Entry


Application Name-> OK.

2. Drag Label, textBox, CheckBox, RadioButton, GroupBox, NumericupDown,


DateTimePicker, ComboBox, and ListBox from toolbox.
 Set Name property of each control i.e. txtUsername, txtEmail, cmbCountry,
lstCities, chkPhysical, rbtnMale, btnSubmit and so on.
 Add items in ListBox by setting items property of ListBox.
3. Add RadioButtons to the GroupBox.
4. Now move towards the code.
 By clicking on the component Button the code file appears and look like this:

5. Add the following code to get the values from the windows components and display to
the user.
6. Now Employee registration is completed. Next we will be working on form validation to
restrict user from bad inputs.
Task: Create Interest Calculator using NumberUpDown Component.
Code Behind:

using System; using System.Windows.Forms;


namespace NumericUpDownTest
{
publicpartialclassInterestCalculatorForm : Form
{
public InterestCalculatorForm()
{
InitializeComponent();
}
privatevoid calculateButton_Click(object sender, EventArgs e)
{

decimal principal;
double rate;
int year;
decimal amount;
string output;

principal = Convert.ToDecimal(principalTextBox.Text);
rate = Convert.ToDouble(interestTextBox.Text);
year = Convert.ToInt32(yearUpDown.Value);

output = "Year\tAmount on Deposit\r\n";

for (int yearCounter = 1; yearCounter <= year; yearCounter++)


{
amount = principal * ((decimal)
Math.Pow((1 + rate / 100), yearCounter));
output += (yearCounter + "\t" +
string.Format("{0:C}", amount) + "\r\n");
}
displayTextBox.Text = output;
}
}}
Reference:
Visual C# 2012, How to program fifth Edition
14.7 Checkboxes and radio buttons
14.5 Label , TextBoxes and Button
14.7 CheckBoxes and RadioButton
15.4 DateTimePicker Control
15.6 ListBox Control
15.7 CheckedListBox Control

Practice Exercise:
Design a student Registration form take student id, student name, gender, email address,
nationality, semester, and department as an input.User appropriate controls in windows form to
take input from the user. On submit button click display the input details in another form.

You might also like