C++ Windows Forms L04 - Controls P3

63
Mohammad Shaker mohammadshakergtr.wordpress.com C++.NET Windows Forms Course @ZGTRShaker C++.NET Windows Forms Course L04 -Controls Part 3

description

C++ Windows Forms L04 - Controls P3 of C++ Windows Forms Light Course

Transcript of C++ Windows Forms L04 - Controls P3

Page 1: C++ Windows Forms L04 - Controls P3

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

TabPage

Page 3: C++ Windows Forms L04 - Controls P3

TabPage (Design Time)

• Design Time …

Page 4: C++ Windows Forms L04 - Controls P3

TabPage (Runtime)

• Runtime …

Page 5: C++ Windows Forms L04 - Controls P3

TabPage-How to change, addtabpages?• At design time …

– Copy \ paste restrictions

Page 6: C++ Windows Forms L04 - Controls P3

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

TabPage-How to change, add tabpages?• If copying and pasting in the selected area like following

Page 8: C++ Windows Forms L04 - Controls P3

TabPage-How to change, addtabpages?• It should be like here …

Page 9: C++ Windows Forms L04 - Controls P3

TabPage-How to change, addtabpages?• Now, at Runtime … it looks like …

Page 10: C++ Windows Forms L04 - Controls P3

TabPage-changing names

Page 11: C++ Windows Forms L04 - Controls P3

TabPage-changing names

Page 12: C++ Windows Forms L04 - Controls P3

TabPage-changing names

Page 13: C++ Windows Forms L04 - Controls P3

ListBox

Page 14: C++ Windows Forms L04 - Controls P3

ListBox (Design time)

• Design time

Page 15: C++ Windows Forms L04 - Controls P3

ListBox (Runtime)

• Runtime

Page 16: C++ Windows Forms L04 - Controls P3

ListBox

Page 17: C++ Windows Forms L04 - Controls P3

ListBox

Page 18: C++ Windows Forms L04 - Controls P3

ListBox

• Let’s have the following small project …

Page 19: C++ Windows Forms L04 - Controls P3

ListBox

Page 20: C++ Windows Forms L04 - Controls P3

ListBox - SelectionMode

• One:– Can only choose one at a time

Page 21: C++ Windows Forms L04 - Controls P3

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

ListBox

Page 23: C++ Windows Forms L04 - Controls P3

ListBox - Coding

Page 24: C++ Windows Forms L04 - Controls P3

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

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

ListBox - Coding

• When changing the course …

Page 27: C++ Windows Forms L04 - Controls P3

CheckBox

Page 28: C++ Windows Forms L04 - Controls P3

CheckBox

• CheckBoxes– Set of non-connected controls– Can choose one or more “checkBox”

Page 29: C++ Windows Forms L04 - Controls P3

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

CheckBox

Page 31: C++ Windows Forms L04 - Controls P3

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

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

CheckedListBox

Page 34: C++ Windows Forms L04 - Controls P3

CheckedListBox

Page 35: C++ Windows Forms L04 - Controls P3

CheckedListBox

• Set of connected “checkBox”es

Page 36: C++ Windows Forms L04 - Controls P3

CheckedListBox

Page 37: C++ Windows Forms L04 - Controls P3

CheckedListBox

Page 38: C++ Windows Forms L04 - Controls P3

CheckedListBox

Page 39: C++ Windows Forms L04 - Controls P3

CheckedListBox

Page 41: C++ Windows Forms L04 - Controls P3

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
Page 43: C++ Windows Forms L04 - Controls P3
Page 44: C++ Windows Forms L04 - Controls P3
Page 45: C++ Windows Forms L04 - Controls P3

Why?!

Page 46: C++ Windows Forms L04 - Controls P3

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

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
Page 49: C++ Windows Forms L04 - Controls P3

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
Page 51: C++ Windows Forms L04 - Controls P3

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

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

CheckedListBox

Page 54: C++ Windows Forms L04 - Controls P3

RadioButton

Page 55: C++ Windows Forms L04 - Controls P3
Page 56: C++ Windows Forms L04 - Controls P3

RadioButton

• “Radio button”s– Set of related “item”s– Can choose only one “at a time”

Page 57: C++ Windows Forms L04 - Controls P3

RadioButton

• Only one can be chosen at a time

Page 58: C++ Windows Forms L04 - Controls P3

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

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

GroupBox

Page 61: C++ Windows Forms L04 - Controls P3

GroupBox

Page 62: C++ Windows Forms L04 - Controls P3

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

That’s it for today!