Successfully reported this slideshow.
Your SlideShare is downloading. ×

C++ Windows Forms L04 - Controls P3

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Loading in …3
×

Check these out next

1 of 63 Ad

More Related Content

Slideshows for you (20)

Similar to C++ Windows Forms L04 - Controls P3 (20)

Advertisement

More from Mohammad Shaker (20)

Recently uploaded (20)

Advertisement

C++ Windows Forms L04 - Controls P3

  1. 1. C++.NET Windows Forms Course L04 -Controls Part 3 Mohammad Shaker mohammadshakergtr.wordpress.com C++.NET Windows Forms Course @ZGTRShaker
  2. 2. TabPage
  3. 3. TabPage (Design Time) • Design Time …
  4. 4. TabPage (Runtime) • Runtime …
  5. 5. TabPage-How to change, add tabpages? • At design time … – Copy paste restrictions
  6. 6. TabPage-How to change, add tabpages? • If copying and pasting in the selected area like following … what will happen?
  7. 7. TabPage-How to change, add tabpages? • If copying and pasting in the selected area like following
  8. 8. TabPage-How to change, add tabpages? • It should be like here …
  9. 9. TabPage-How to change, add tabpages? • Now, at Runtime … it looks like …
  10. 10. TabPage-changing names
  11. 11. TabPage-changing names
  12. 12. TabPage-changing names
  13. 13. ListBox
  14. 14. ListBox (Design time) • Design time
  15. 15. ListBox (Runtime) • Runtime
  16. 16. ListBox
  17. 17. ListBox
  18. 18. ListBox • Let’s have the following small project …
  19. 19. ListBox
  20. 20. ListBox - SelectionMode • One: – Can only choose one at a time
  21. 21. ListBox - SelectionMode • MultiSimple: – No ctrl needed! • MultiExtended: – ctrl needed when selecting more that one – Auto select changing
  22. 22. ListBox
  23. 23. ListBox - Coding
  24. 24. private: System::Void listBox1_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) { if (listBox1->SelectedIndex == 0) { textBox1->Text = "C++ Course is a course about c++!:D"; } } What’s will happen now? What will happen when selecting another option after selecting C++?
  25. 25. ListBox - Coding • It’s a runtime error if selecting nothing and then pressing button2. Otherwise it works properly. private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) { textBox1->Text =listBox1->SelectedItem->ToString(); }
  26. 26. ListBox - Coding • When changing the course …
  27. 27. CheckBox
  28. 28. CheckBox • CheckBoxes – Set of non-connected controls – Can choose one or more “checkBox”
  29. 29. CheckBox private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { if (checkBox1->Checked == true ) { MessageBox::Show("You chose " + checkBox1->Text ); } } private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { if (checkBox1->Checked == true ) { MessageBox::Show("You chose " + “English” ); } } private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { if (checkBox1->Checked == true ) { MessageBox::Show("You chose English” ); } }
  30. 30. CheckBox
  31. 31. CheckBox private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { if (checkBox1->Checked == true ) { MessageBox::Show("You chose " + sender->ToString() ); } }
  32. 32. CheckBox private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { if (checkBox1->Checked == true ) { MessageBox::Show("You chose " + e->ToString() ); } }
  33. 33. CheckedListBox
  34. 34. CheckedListBox
  35. 35. CheckedListBox • Set of connected “checkBox”es
  36. 36. CheckedListBox
  37. 37. CheckedListBox
  38. 38. CheckedListBox
  39. 39. CheckedListBox
  40. 40. CheckedListBox • Hierarchy … – System::Object System::MarshalByRefObject System.ComponentModel::Component System.Windows.Forms::Control System.Windows.Forms::ListControl System.Windows.Forms::ListBox System.Windows.Forms::CheckedListBox
  41. 41. CheckedListBox • Let’s have the following code … private: System::Void button1_Click(System::Object^ System::EventArgs^ e) { if (checkedListBox1->SelectedIndex == 1 ) { textBox1->Text = "WOOOW"; } } sender,
  42. 42. Why?!
  43. 43. CheckedListBox • The same story goes with this: private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { if (checkedListBox1->SelectedItem == "French" ) { textBox1->Text = "WOOOW"; } }
  44. 44. CheckedListBox • So, we do this: private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { if (checkedListBox1->GetItemChecked(1) == true) { textBox1->Text = "WoW "; } }
  45. 45. CheckedListBox • Now, let’s see this: private: System::Void button1_Click(System::Object^ System::EventArgs^ e) { checkedListBox1->Items->Add("Spanish"); } sender,
  46. 46. CheckedListBox • And ofcourse, we can do this! private: System::Void button1_Click(System::Object^ System::EventArgs^ e) { checkedListBox1->Items->Add(textBox1->Text); } sender,
  47. 47. CheckedListBox private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { if (checkedListBox1->Items[0]->ToString() == "English") { textBox1->Text = "WoW "; } }
  48. 48. CheckedListBox
  49. 49. RadioButton
  50. 50. RadioButton • “Radio button”s – Set of related “item”s – Can choose only one “at a time”
  51. 51. RadioButton • Only one can be chosen at a time
  52. 52. RadioButton private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { if (radioButton1->Checked == true ) MessageBox::Show("I wanna drink some water"); }
  53. 53. RadioButton • So, how to break the restriction and select more than one radioButton? There’s sth called the “GroupBox” from “Containers” section.
  54. 54. GroupBox
  55. 55. GroupBox
  56. 56. GroupBox • Now, we can choose more than one RadioButton • But we can only choose one RadioButton from “each” GroupBox.
  57. 57. That’s it for today!

×