For Beginners
Demo Projects:
• Employee Information Form (Using advance controls)
What will you learn?
• Using following controls:
o Masked Textbox
o Multiline Textbox
o ComboBox, ListBox, CheckBoxList
o DateTimePicker
o NumericUpDown
o RadioButton
• Adding Items to ComboBox, ListBox and CheckBoxList Statically and Dynamically
• Enabling Autocomplete feature in ComboBox
• Getting Selected items form ComboBox, ListBox and CheckBoxList
• Clearing or resetting all these controls to default values.
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Windows Forms For Beginners Part - 3
1. Demo Projects:
• Employee Information Form (Using advance controls)
What will you learn?
• Using following controls:
o Masked Textbox
o Multiline Textbox
o ComboBox, ListBox
o DateTimePicker
o NumericUpDown
o RadioButton
• Adding Items to ComboBox
Dynamically
• Enabling Autocomplete
• Getting Selected items form ComboBox, ListBox and CheckBoxList
• Clearing or resetting all these controls to default values.
Windows Forms for Beginners
www.dotnetvideotutorial.com
Employee Information Form (Using advance controls)
Using following controls:
Textbox
Multiline Textbox
ListBox, CheckBoxList
NumericUpDown
Adding Items to ComboBox, ListBox and CheckBoxList Statically and
Autocomplete feature in ComboBox
Getting Selected items form ComboBox, ListBox and CheckBoxList
Clearing or resetting all these controls to default values.
Bhushan Mulmule
bhushan.mulmule@gmail.com
www.dotnetvideotutorial.com
Windows Forms for Beginners
Part 3
Statically and
Getting Selected items form ComboBox, ListBox and CheckBoxList
Bhushan Mulmule
bhushan.mulmule@gmail.com
www.dotnetvideotutorial.com
Windows Forms for Beginners
3. www.dotnetvideotutorial.com
Instructions:
• MaskedTextBox allows defining format for input using Mask property.
o Mask = 0000: To make it compulsory to user to enter 4 digit employee
number.
• Multiline property of textbox need to be set to true in order to enter multiple
lines in textbox
• ComboBox allows user to select item from predefined list
o Items property holds multiple items. When you will click on Items
property Collection Editor Window will open where you can add multiple
items (one item per line)
o AutoCompleteSource and AutoCompleteMode enables AutoComplete
feature of combobox. So that user can type in ComboBox and can select
item from matching suggestion list.
• ListBox is same as ComboBox except it displays multiple items as list.
o Items property can be used to populate control same as ComboBox.
o In this example we are populating it dynamically by writing function
PopulateStates and calling it from Form_Load Event
• DateTimePicker enables user to select date visually.
o Format property provides various predefined formats for date
o CustomFormat property allows to define custom format.
o To use CustomFormat; Format property need to set to CustomFormat
• NumericUpdown enables user to select numeric value from predefined range
o Minimum and Maximum properties need to be set
• Radio buttons for gender has to be in group box to specify that they are in same
group and only one should get selected out of them.
• CheckBoxList allows to select multiple items easily from predefined list
o We can populate it statically using item property or dynamically using
code as for ListBox.
o We will populate it using items property
o We will also
• Details textbox is nothing but textbox with multiline property set to true.
o To show all the details on this textbox first we will collect all the
information in string and then will assign it to details textbox.
4. www.dotnetvideotutorial.com
o Note: Strings are immutable and creates new object with every
concatenation. So this can be done better using StringBuilder Class.
(When you need to concatenate string number of times you should use
StringBuilder Class) Read about it and try to implement same thing using
StringBuilder class after finishing this walkthrough.
Step 3: Add event handlers for buttons
1. Double Click on Form to go to code window. Create function PopulateStates
outside form_load event
private void PopulateStates()
{
lstStates.Items.Add("Maharashtra");
lstStates.Items.Add("MP");
lstStates.Items.Add("Punjab");
lstStates.Items.Add("Karnataka");
lstStates.Items.Add("Goa");
}
2. Call PopulateSates from Form_Load Event
private void frmEmployeeDetails_Load(object sender, EventArgs e)
{
PopulateStates();
}
3. Double click on OK button:
private void btnOK_Click(object sender, EventArgs e)
{
string details;
details = "EmpNo: " + mskTxtEmpNo.Text;
details += "rnName: " + txtName.Text;
details += "rnAddress: " + txtAddress.Text;
details += "rnCity: " + cmbCity.SelectedItem;
details += "rnState: " + lstState.SelectedItem;
details += "rnDOB: " + dtpDOB.Value.ToShortDateString();
details += "rnAge: " + numAge.Value.ToString();
string gender = radMale.Checked ? "Male" : "Female";
details += "rnGender: " + gender;