C++.NET
Windows Forms Course
L05 -Controls Part 4

Mohammad Shaker
mohammadshakergtr.wordpress.com
C++.NET Windows Forms C...
Focus Method
Focus Method
• What will happen now?
private: System::Void button1_Click_3(System::Object^
System::EventArgs^ e)
{
textBox...
Focus Method
Before clicking button1

After clicking button1
Focus Method
• We sometimes use the following
private: System::Void button1_Click_3(System::Object^
System::EventArgs^ e)
...
Focus Method
Before clicking button1

After clicking button1
Focus Method
• The Windows Forms controls in the following list are not
selectable. Controls derived from these controls a...
Focus Method
public: void ControlSetFocus(Control^ control)
{
// Set focus to the control, if it can receive focus.
if (co...
DataGridVeiw
DataGridVeiw
• Matrix
• DataBase
• DataBind (DataSource)
DataGridVeiw
DataGridVeiw
• Dock in parent container
DataGridVeiw
DataGridVeiw
DataGridVeiw
DataGridVeiw
private: System::Void button1_Click_1(System::Object^
System::EventArgs^ e)
{
dataGridView1[0,0]->Value = 3;
...
DataGridVeiw
• Is it the same with columns? No need to!
private: System::Void button1_Click_1(System::Object^ sender,
Syst...
DataGridVeiw
StatusBar
StatusBar
StatusBar
StatusBar
StatusBar
StatusBar
• Can add more than one!
StatusBar
• Let’s have the following …
StatusBar
private: System::Void button1_Click_5(System::Object^ sender,
System::EventArgs^ e)
{
toolStripStatusLabel1->Tex...
StatusBar

Before clicking button1

After clicking button1
StatusBar
• What will happen now?
private: System::Void Form1_MouseMove(System::Object^
System::Windows::Forms::MouseEvent...
MenuStrip
MenuStrip - Runtime

Has Events Like any
other
Timer
Timer
Timer
• Consider this:
private: System::Void button1_Click(System::Object^
System::EventArgs^ e)
{
timer1->enabled = true;...
Timer
• Before clicking the “start” button
Timer
• After clicking the “start” button
Quick App
OpenFileDialog
OpenFileDialog
private: System::Void button1_Click(System::Object^
System::EventArgs^ e)
{
openFileDialog1->ShowDialog();
...
OpenFileDialog
OpenFileDialog
• Note that openFileDialog won’t open any file! Just a dialog!
private: System::Void button1_Click(System::...
OpenFileDialog
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
if(
openFileDialog1->Sh...
OpenFileDialog
OpenFileDialog - Filters
• text files (*.txt) |*.txt
• All files (*.*) | *.*
OpenFileDialog - Folders
// If a file is not opened then set the initial directory to the
// FolderBrowserDialog::Selected...
SaveFileDialog
OpenFileDialog
using namespace System::IO;
private:
void button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
S...
SaveFileDialog
using namespace System::IO;
private:
void button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
S...
That’s it for today!
C++ Windows Forms L05 - Controls P4
C++ Windows Forms L05 - Controls P4
C++ Windows Forms L05 - Controls P4
C++ Windows Forms L05 - Controls P4
C++ Windows Forms L05 - Controls P4
C++ Windows Forms L05 - Controls P4
C++ Windows Forms L05 - Controls P4
C++ Windows Forms L05 - Controls P4
C++ Windows Forms L05 - Controls P4
C++ Windows Forms L05 - Controls P4
C++ Windows Forms L05 - Controls P4
C++ Windows Forms L05 - Controls P4
C++ Windows Forms L05 - Controls P4
C++ Windows Forms L05 - Controls P4
C++ Windows Forms L05 - Controls P4
C++ Windows Forms L05 - Controls P4
C++ Windows Forms L05 - Controls P4
Upcoming SlideShare
Loading in …5
×

C++ Windows Forms L05 - Controls P4

688 views

Published on

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

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
688
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
80
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

C++ Windows Forms L05 - Controls P4

  1. 1. C++.NET Windows Forms Course L05 -Controls Part 4 Mohammad Shaker mohammadshakergtr.wordpress.com C++.NET Windows Forms Course @ZGTRShaker
  2. 2. Focus Method
  3. 3. Focus Method • What will happen now? private: System::Void button1_Click_3(System::Object^ System::EventArgs^ e) { textBox2->Focus() ; } sender,
  4. 4. Focus Method Before clicking button1 After clicking button1
  5. 5. Focus Method • We sometimes use the following private: System::Void button1_Click_3(System::Object^ System::EventArgs^ e) { if (textBox2->CanFocus == true ) { textBox2->Focus() ; } } sender, • Why? And what will happen? Cause some controlls don’t have the Focus method as one of their members
  6. 6. Focus Method Before clicking button1 After clicking button1
  7. 7. 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)
  8. 8. Focus Method public: void ControlSetFocus(Control^ control) { // Set focus to the control, if it can receive focus. if (control->CanFocus) control->Focus(); }
  9. 9. DataGridVeiw
  10. 10. DataGridVeiw • Matrix • DataBase • DataBind (DataSource)
  11. 11. DataGridVeiw
  12. 12. DataGridVeiw • Dock in parent container
  13. 13. DataGridVeiw
  14. 14. DataGridVeiw
  15. 15. DataGridVeiw
  16. 16. DataGridVeiw private: System::Void button1_Click_1(System::Object^ System::EventArgs^ e) { dataGridView1[0,0]->Value = 3; } sender,
  17. 17. 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(); }
  18. 18. DataGridVeiw
  19. 19. StatusBar
  20. 20. StatusBar
  21. 21. StatusBar
  22. 22. StatusBar
  23. 23. StatusBar
  24. 24. StatusBar • Can add more than one!
  25. 25. StatusBar • Let’s have the following …
  26. 26. 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"; }
  27. 27. StatusBar Before clicking button1 After clicking button1
  28. 28. StatusBar • What will happen now? private: System::Void Form1_MouseMove(System::Object^ System::Windows::Forms::MouseEventArgs^ e) { toolStripProgressBar1->PerformStep(); } sender,
  29. 29. MenuStrip
  30. 30. MenuStrip - Runtime Has Events Like any other
  31. 31. Timer
  32. 32. Timer
  33. 33. Timer • Consider this: private: System::Void button1_Click(System::Object^ System::EventArgs^ e) { timer1->enabled = true; } sender, • What should happen now? private: System::Void timer1_Tick(System::Object^ System::EventArgs^ e) { progressBar1->PerformStep(); } sender,
  34. 34. Timer • Before clicking the “start” button
  35. 35. Timer • After clicking the “start” button
  36. 36. Quick App
  37. 37. OpenFileDialog
  38. 38. OpenFileDialog private: System::Void button1_Click(System::Object^ System::EventArgs^ e) { openFileDialog1->ShowDialog(); } sender,
  39. 39. OpenFileDialog
  40. 40. 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 ; } }
  41. 41. OpenFileDialog private: 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 ; } }
  42. 42. OpenFileDialog
  43. 43. OpenFileDialog - Filters • text files (*.txt) |*.txt • All files (*.*) | *.*
  44. 44. 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; }
  45. 45. SaveFileDialog
  46. 46. OpenFileDialog using namespace System::IO; 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(); } } }
  47. 47. SaveFileDialog using namespace System::IO; 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(); } } }
  48. 48. That’s it for today!

×