Thursday, September 20, 2012

Windows Form Controls (Part 2)

Lets do something more with the previous tutorial. Open up the previous WindowsControlsTutorials solution.
  1. Add a comboBox from the toolbox to the Form.
  2. Change the Text Property of the button from Show to Add.
  3. Double click on the button and write this
  4. comboBox1.Items.Add(textBox1.Text + " " + textBox2.Text + " " + textBox3.Text); MessageBox.Show("Name Added");
  5. The first line will add a item in the comboBox1 with the given values in the textBox's. The second line will show a notification through a messageBox that a name has been added successfully in the comboBox.
  6. Go back to Form1.cs[Design] tab and double click on the comboBox.
  7. this will generate the event
  8. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) {}
  9. Write down MessageBox.Show(comboBox1.Text); in the curly braces.
  10. Start Debugging.
  11. Give values and press Add.
  12. This will enter a item in the comboBox with the given text in the textBox's.
  13. Add as many names as you like.
  14. Now select a item from the comboBox.
  15. A messageBox will popup and show the Text of the comboBox selected index. 
  16. In this tutorial when you cahnge the comboBox selected index the comboBox1_SelectedIndexChanged event fires up and show the index item Text in the messageBox.






No comments:

Post a Comment