c++ windows forms l04 - controls p3
DESCRIPTION
C++ Windows Forms L04 - Controls P3 of C++ Windows Forms Light CourseTRANSCRIPT
![Page 1: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/1.jpg)
Mohammad Shakermohammadshakergtr.wordpress.com
C++.NET Windows Forms Course@ZGTRShaker
C++.NET Windows Forms Course
L04 -Controls Part 3
![Page 2: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/2.jpg)
TabPage
![Page 3: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/3.jpg)
TabPage (Design Time)
• Design Time …
![Page 4: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/4.jpg)
TabPage (Runtime)
• Runtime …
![Page 5: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/5.jpg)
TabPage-How to change, addtabpages?• At design time …
– Copy \ paste restrictions
![Page 6: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/6.jpg)
TabPage-How to change, add tabpages?• If copying and pasting in the selected area like following …
what will happen?
![Page 7: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/7.jpg)
TabPage-How to change, add tabpages?• If copying and pasting in the selected area like following
![Page 8: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/8.jpg)
TabPage-How to change, addtabpages?• It should be like here …
![Page 9: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/9.jpg)
TabPage-How to change, addtabpages?• Now, at Runtime … it looks like …
![Page 10: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/10.jpg)
TabPage-changing names
![Page 11: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/11.jpg)
TabPage-changing names
![Page 12: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/12.jpg)
TabPage-changing names
![Page 13: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/13.jpg)
ListBox
![Page 14: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/14.jpg)
ListBox (Design time)
• Design time
![Page 15: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/15.jpg)
ListBox (Runtime)
• Runtime
![Page 16: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/16.jpg)
ListBox
![Page 17: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/17.jpg)
ListBox
![Page 18: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/18.jpg)
ListBox
• Let’s have the following small project …
![Page 19: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/19.jpg)
ListBox
![Page 20: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/20.jpg)
ListBox - SelectionMode
• One:– Can only choose one at a time
![Page 21: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/21.jpg)
ListBox - SelectionMode
• MultiSimple: – No ctrl needed!
• MultiExtended:– ctrl needed when selecting more that one– Auto select changing
![Page 22: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/22.jpg)
ListBox
![Page 23: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/23.jpg)
ListBox - Coding
![Page 24: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/24.jpg)
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++?
![Page 25: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/25.jpg)
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();
}
![Page 26: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/26.jpg)
ListBox - Coding
• When changing the course …
![Page 27: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/27.jpg)
CheckBox
![Page 28: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/28.jpg)
CheckBox
• CheckBoxes– Set of non-connected controls– Can choose one or more “checkBox”
![Page 29: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/29.jpg)
CheckBoxprivate: 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” );
}
}
![Page 30: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/30.jpg)
CheckBox
![Page 31: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/31.jpg)
CheckBoxprivate: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
if (checkBox1->Checked == true )
{
MessageBox::Show("You chose " + sender->ToString() );
}
}
![Page 32: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/32.jpg)
CheckBoxprivate: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
if (checkBox1->Checked == true )
{
MessageBox::Show("You chose " + e->ToString() );
}
}
![Page 33: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/33.jpg)
CheckedListBox
![Page 34: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/34.jpg)
CheckedListBox
![Page 35: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/35.jpg)
CheckedListBox
• Set of connected “checkBox”es
![Page 36: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/36.jpg)
CheckedListBox
![Page 37: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/37.jpg)
CheckedListBox
![Page 38: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/38.jpg)
CheckedListBox
![Page 39: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/39.jpg)
CheckedListBox
![Page 40: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/40.jpg)
CheckedListBox
• Hierarchy …– System::Object
System::MarshalByRefObjectSystem.ComponentModel::ComponentSystem.Windows.Forms::ControlSystem.Windows.Forms::ListControlSystem.Windows.Forms::ListBoxSystem.Windows.Forms::CheckedListBox
![Page 41: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/41.jpg)
CheckedListBox
• Let’s have the following code …
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
if (checkedListBox1->SelectedIndex == 1 )
{
textBox1->Text = "WOOOW";
}
}
![Page 42: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/42.jpg)
![Page 43: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/43.jpg)
![Page 44: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/44.jpg)
![Page 45: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/45.jpg)
Why?!
![Page 46: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/46.jpg)
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";
}
}
![Page 47: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/47.jpg)
CheckedListBox
• So, we do this:
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
if (checkedListBox1->GetItemChecked(1) == true)
{
textBox1->Text = "WoW ";
}
}
![Page 48: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/48.jpg)
![Page 49: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/49.jpg)
CheckedListBox
• Now, let’s see this: private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
checkedListBox1->Items->Add("Spanish");
}
![Page 50: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/50.jpg)
![Page 51: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/51.jpg)
CheckedListBox
• And ofcourse, we can do this! private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
checkedListBox1->Items->Add(textBox1->Text);
}
![Page 52: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/52.jpg)
CheckedListBox
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
if (checkedListBox1->Items[0]->ToString() == "English")
{
textBox1->Text = "WoW ";
}
}
![Page 53: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/53.jpg)
CheckedListBox
![Page 54: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/54.jpg)
RadioButton
![Page 55: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/55.jpg)
![Page 56: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/56.jpg)
RadioButton
• “Radio button”s– Set of related “item”s– Can choose only one “at a time”
![Page 57: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/57.jpg)
RadioButton
• Only one can be chosen at a time
![Page 58: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/58.jpg)
RadioButtonprivate: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
if (radioButton1->Checked == true )
MessageBox::Show("I wanna drink some water");
}
![Page 59: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/59.jpg)
RadioButton
• So, how to break the restriction and select more than one radioButton?There’s sth called the “GroupBox” from “Containers” section.
![Page 60: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/60.jpg)
GroupBox
![Page 61: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/61.jpg)
GroupBox
![Page 62: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/62.jpg)
GroupBox
• Now, we can choose more than one RadioButton• But we can only choose one RadioButton from “each”
GroupBox.
![Page 63: C++ Windows Forms L04 - Controls P3](https://reader034.vdocuments.net/reader034/viewer/2022050720/545bdc14af7959b9098b4568/html5/thumbnails/63.jpg)
That’s it for today!