c++ windows forms l05 - controls p4
DESCRIPTION
C++ Windows Forms L05 - Controls P4 of C++ Windows Forms Light CourseTRANSCRIPT
![Page 1: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/1.jpg)
Mohammad Shakermohammadshakergtr.wordpress.com
C++.NET Windows Forms Course@ZGTRShaker
C++.NET Windows Forms Course
L05 -Controls Part 4
![Page 2: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/2.jpg)
![Page 3: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/3.jpg)
Focus Method
![Page 4: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/4.jpg)
Focus Method
• What will happen now? private: System::Void button1_Click_3(System::Object^ sender,
System::EventArgs^ e)
{
textBox2->Focus() ;
}
![Page 5: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/5.jpg)
Focus Method
After clicking button1Before clicking button1
![Page 6: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/6.jpg)
Focus Method
• We sometimes use the following
• Why? And what will happen? Cause some controlls don’t have the Focus method as one of
their members
private: System::Void button1_Click_3(System::Object^ sender,
System::EventArgs^ e)
{
if (textBox2->CanFocus == true )
{
textBox2->Focus() ;
}
}
![Page 7: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/7.jpg)
Focus Method
After clicking button1Before clicking button1
![Page 8: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/8.jpg)
Focus Method
• The Windows Forms controls in the following list are not selectable. Controls derived from these controls are also not selectable.
• Panel• GroupBox• PictureBox• ProgressBar• Splitter• Label• LinkLabel (when there is no link present in the control)
![Page 9: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/9.jpg)
Focus Method
public: void ControlSetFocus(Control^ control)
{
// Set focus to the control, if it can receive focus.
if (control->CanFocus)
control->Focus();
}
![Page 10: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/10.jpg)
DataGridVeiw
![Page 11: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/11.jpg)
DataGridVeiw
• Matrix• DataBase• DataBind (DataSource)
![Page 12: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/12.jpg)
DataGridVeiw
![Page 13: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/13.jpg)
DataGridVeiw
• Dock in parent container
![Page 14: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/14.jpg)
DataGridVeiw
![Page 15: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/15.jpg)
DataGridVeiw
![Page 16: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/16.jpg)
DataGridVeiw
![Page 17: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/17.jpg)
![Page 18: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/18.jpg)
![Page 19: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/19.jpg)
DataGridVeiw
private: System::Void button1_Click_1(System::Object^ sender,
System::EventArgs^ e)
{
dataGridView1[0,0]->Value = 3;
}
![Page 20: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/20.jpg)
DataGridVeiw
• Is it the same with columns? No need to!
private: System::Void button1_Click_1(System::Object^ sender,
System::EventArgs^ e)
{
textBox1->Text=dataGridView1->Rows[0]->Cells[1]->Value-> ToString();
}
![Page 21: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/21.jpg)
DataGridVeiw
![Page 22: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/22.jpg)
StatusBar
![Page 23: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/23.jpg)
StatusBar
![Page 24: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/24.jpg)
StatusBar
![Page 25: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/25.jpg)
StatusBar
![Page 26: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/26.jpg)
StatusBar
![Page 27: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/27.jpg)
StatusBar
• Can add more than one!
![Page 28: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/28.jpg)
![Page 29: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/29.jpg)
![Page 30: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/30.jpg)
![Page 31: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/31.jpg)
StatusBar
• Let’s have the following …
![Page 32: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/32.jpg)
StatusBar
private: System::Void button1_Click_5(System::Object^ sender,
System::EventArgs^ e)
{
toolStripStatusLabel1->Text = "You are clicking the button and you
seem hungy:D";
}
![Page 33: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/33.jpg)
StatusBar
Before clicking button1 After clicking button1
![Page 34: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/34.jpg)
StatusBar
• What will happen now? private: System::Void Form1_MouseMove(System::Object^ sender,
System::Windows::Forms::MouseEventArgs^ e)
{
toolStripProgressBar1->PerformStep();
}
![Page 35: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/35.jpg)
![Page 36: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/36.jpg)
![Page 37: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/37.jpg)
![Page 38: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/38.jpg)
![Page 39: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/39.jpg)
MenuStrip
![Page 40: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/40.jpg)
MenuStrip - Runtime
Has Events Like any other
![Page 41: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/41.jpg)
![Page 42: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/42.jpg)
Timer
![Page 43: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/43.jpg)
![Page 44: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/44.jpg)
Timer
![Page 45: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/45.jpg)
Timer
• Consider this:
• What should happen now?
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
timer1->enabled = true;
}
private: System::Void timer1_Tick(System::Object^ sender,
System::EventArgs^ e)
{
progressBar1->PerformStep();
}
![Page 46: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/46.jpg)
Timer
• Before clicking the “start” button
![Page 47: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/47.jpg)
Timer
• After clicking the “start” button
![Page 48: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/48.jpg)
Quick App
![Page 49: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/49.jpg)
OpenFileDialog
![Page 50: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/50.jpg)
OpenFileDialog
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
openFileDialog1->ShowDialog();
}
![Page 51: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/51.jpg)
![Page 52: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/52.jpg)
OpenFileDialog
![Page 53: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/53.jpg)
OpenFileDialog
• Note that openFileDialog won’t open any file! Just a dialog!private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
if (openFileDialog1->ShowDialog()==(System::Windows::Forms::DialogResult::OK))
{
textBox1->Text = openFileDialog1->FileName ;
}
}
![Page 54: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/54.jpg)
OpenFileDialogprivate: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
if(
openFileDialog1->ShowDialog()==(System::Windows::Forms::DialogResult::OK))
{
textBox1->Text = openFileDialog1->FileName ;
openFileDialog1->ShowReadOnly = true ;
}
}
![Page 55: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/55.jpg)
OpenFileDialog
![Page 56: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/56.jpg)
OpenFileDialog - Filters
• text files (*.txt) |*.txt• All files (*.*) | *.*
![Page 57: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/57.jpg)
OpenFileDialog - Folders// If a file is not opened then set the initial directory to the// FolderBrowserDialog::SelectedPath value.if ( !fileOpened ){
openFileDialog1->InitialDirectory = folderBrowserDialog1->SelectedPath;openFileDialog1->FileName = nullptr;
}
![Page 58: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/58.jpg)
![Page 59: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/59.jpg)
SaveFileDialog
![Page 60: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/60.jpg)
OpenFileDialog
private:void button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ ){
Stream^ myStream;OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;
openFileDialog1->InitialDirectory = "c:\\";openFileDialog1->Filter = "txt files (*.txt)|*.txt|All files
(*.*)|*.*";openFileDialog1->FilterIndex = 2;openFileDialog1->RestoreDirectory = true;
if ( openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK )
{if ( (myStream = openFileDialog1->OpenFile())!= nullptr ){
// Insert code to read the stream here.myStream->Close();
}}
}
using namespace System::IO;
![Page 61: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/61.jpg)
![Page 62: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/62.jpg)
![Page 63: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/63.jpg)
SaveFileDialog
private:
void button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
Stream^ myStream;
SaveFileDialog^ saveFileDialog1 = gcnew SaveFileDialog;
saveFileDialog1->Filter = "txt files (*.txt)|*.txt|All files
(*.*)|*.*";
saveFileDialog1->FilterIndex = 2;
saveFileDialog1->RestoreDirectory = true;
if ( saveFileDialog1->ShowDialog() ==
System::Windows::Forms::DialogResult::OK)
{
if ( (myStream = saveFileDialog1->OpenFile())!= nullptr)
{
// Code to write the stream goes here.
myStream->Close();
}
}
}
using namespace System::IO;
![Page 64: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/64.jpg)
![Page 65: C++ Windows Forms L05 - Controls P4](https://reader033.vdocument.in/reader033/viewer/2022061214/549cb19eb4795991318b4840/html5/thumbnails/65.jpg)
That’s it for today!