65
Mohammad Shaker mohammadshakergtr.wordpress.com C++.NET Windows Forms Course @ZGTRShaker C++.NET Windows Forms Course L05 -Controls Part 4

C++ Windows Forms L05 - Controls P4

Embed Size (px)

DESCRIPTION

C++ Windows Forms L05 - Controls P4 of C++ Windows Forms Light Course

Citation preview

Page 1: C++ Windows Forms L05 - Controls P4

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
Page 3: C++ Windows Forms L05 - Controls P4

Focus Method

Page 4: C++ Windows Forms L05 - Controls P4

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

Focus Method

After clicking button1Before clicking button1

Page 6: C++ Windows Forms L05 - Controls P4

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

Focus Method

After clicking button1Before clicking button1

Page 9: C++ Windows Forms L05 - Controls P4

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

DataGridVeiw

Page 11: C++ Windows Forms L05 - Controls P4

DataGridVeiw

• Matrix• DataBase• DataBind (DataSource)

Page 12: C++ Windows Forms L05 - Controls P4

DataGridVeiw

Page 13: C++ Windows Forms L05 - Controls P4

DataGridVeiw

• Dock in parent container

Page 14: C++ Windows Forms L05 - Controls P4

DataGridVeiw

Page 15: C++ Windows Forms L05 - Controls P4

DataGridVeiw

Page 16: C++ Windows Forms L05 - Controls P4

DataGridVeiw

Page 17: C++ Windows Forms L05 - Controls P4
Page 18: C++ Windows Forms L05 - Controls P4
Page 19: C++ Windows Forms L05 - Controls P4

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

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

DataGridVeiw

Page 22: C++ Windows Forms L05 - Controls P4

StatusBar

Page 23: C++ Windows Forms L05 - Controls P4

StatusBar

Page 24: C++ Windows Forms L05 - Controls P4

StatusBar

Page 25: C++ Windows Forms L05 - Controls P4

StatusBar

Page 26: C++ Windows Forms L05 - Controls P4

StatusBar

Page 27: C++ Windows Forms L05 - Controls P4

StatusBar

• Can add more than one!

Page 28: C++ Windows Forms L05 - Controls P4
Page 29: C++ Windows Forms L05 - Controls P4
Page 30: C++ Windows Forms L05 - Controls P4
Page 31: C++ Windows Forms L05 - Controls P4

StatusBar

• Let’s have the following …

Page 32: C++ Windows Forms L05 - Controls P4

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

StatusBar

Before clicking button1 After clicking button1

Page 34: C++ Windows Forms L05 - Controls P4

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
Page 36: C++ Windows Forms L05 - Controls P4
Page 37: C++ Windows Forms L05 - Controls P4
Page 38: C++ Windows Forms L05 - Controls P4
Page 39: C++ Windows Forms L05 - Controls P4

MenuStrip

Page 40: C++ Windows Forms L05 - Controls P4

MenuStrip - Runtime

Has Events Like any other

Page 41: C++ Windows Forms L05 - Controls P4
Page 42: C++ Windows Forms L05 - Controls P4

Timer

Page 43: C++ Windows Forms L05 - Controls P4
Page 44: C++ Windows Forms L05 - Controls P4

Timer

Page 45: C++ Windows Forms L05 - Controls P4

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

Timer

• Before clicking the “start” button

Page 47: C++ Windows Forms L05 - Controls P4

Timer

• After clicking the “start” button

Page 48: C++ Windows Forms L05 - Controls P4

Quick App

Page 49: C++ Windows Forms L05 - Controls P4

OpenFileDialog

Page 50: C++ Windows Forms L05 - Controls P4

OpenFileDialog

private: System::Void button1_Click(System::Object^ sender,

System::EventArgs^ e)

{

openFileDialog1->ShowDialog();

}

Page 51: C++ Windows Forms L05 - Controls P4
Page 52: C++ Windows Forms L05 - Controls P4

OpenFileDialog

Page 53: C++ Windows Forms L05 - Controls P4

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

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

OpenFileDialog

Page 56: C++ Windows Forms L05 - Controls P4

OpenFileDialog - Filters

• text files (*.txt) |*.txt• All files (*.*) | *.*

Page 57: C++ Windows Forms L05 - Controls P4

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
Page 59: C++ Windows Forms L05 - Controls P4

SaveFileDialog

Page 60: C++ Windows Forms L05 - Controls P4

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
Page 62: C++ Windows Forms L05 - Controls P4
Page 63: C++ Windows Forms L05 - Controls P4

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
Page 65: C++ Windows Forms L05 - Controls P4

That’s it for today!