C++.NET
Windows Forms Course
L03 – Controls Part 2

Mohammad Shaker
mohammadshakergtr.wordpress.com
C++.NET Windows Forms ...
Switching Between Forms
It’s another form..
Switching between forms
Switching to a another forms
• Let’s consider that we want to have two forms and we want
to switch between them
– #1: Firs...
Switching Back to Form1
• In “Form2.h”
namespace MyTestPro {
ref class Form1;
public: Form1 ^FPtr;
Form2(Form1 ^f)
{
Initi...
Switching Back to Form1
• In “Form2.cpp”
#include "StdAfx.h"
#include "Form2.h"
#include "Form1.h”
namespace MyTestPro {
S...
Peak on Drawing Class
Point & Size
Peak on Drawing::Point
• What will happen now?

private: System::Void button1_Click(System::Object^
sender, System::EventA...
Peak on Drawing::Point
Peak on Drawing::Point
• What will happen now?
private: System::Void button1_Click(System::Object^
System::EventArgs^ e)
{...
Drawing::Point
Helpers
Helpers

So, what should
we do?
Point and Size
• Can we do this? Yes!
private: System::Void button1_Click_1(System::Object^
System::EventArgs^ e)
{
Drawin...
Point and Size
• Can we do this?
private: System::Void button1_Click_1(System::Object^
System::EventArgs^ e)
{
Drawing::Si...
Helpers
Point and Size
private: System::Void button1_Click_1(System::Object^
sender, System::EventArgs^ e)
{
this->Size= Drawing::...
Helpers
Point and Size
Label
Label
• Properties:
Name, Text, Font, image, Location, Size, TabStop, TabIndex,
Visible, BackColor

• Event:
MouseClick, M...
TextBox
TextBox
• Properties:
Name, Text, Font, image, Location, Size, TabStop, TabIndex,
Visible, BackColor, MultiLine, ScrollBar...
Panel
Panel
• Properties:
Name, Text, Font, image, Location, Size, TabStop, TabIndex,
Visible, BackColor, Border Style, AutoSize...
TrackBar
TrackBar
TrackBar
TrackBar

Keyboard keys (Arrows)
Number of ticks between tick
marks
position
TrackBar
• What will happen now?
private: System::Void trackBar1_Scroll(System::Object^
System::EventArgs^ e)
{
textBox1->...
TrackBar
ProgressBar
ProgressBar
ProgressBar
ProgressBar
ProgressBar
• Increment the progressBar and perform the “performStep()”
• What will happen when pressing the button?
priva...
ProgressBar
• What will happen now when pressing the button, repeatedly?
private: System::Void button1_Click_4(System::Obj...
ProgressBar

Before clicking button1

After clicking button1 for 1st time

After clicking button1 for 2nd time
ProgressBar
• Another example:
– The following code example uses a ProgressBar control to display the
progress of a file c...
private:
void CopyWithProgress( array<String^>^filenames )
{
// Display the ProgressBar control.
pBar1->Visible= true;
// ...
NumericUpDown
NumericUpDown properties
The interval

Starting value
NumericUpDown - coding
• Text property
private: System::Void button1_Click_1(System::Object^
System::EventArgs^ e)
{
textB...
NumericUpDown - coding
• Everything ok?

private: System::Void textBox1_TextChanged(System::Object^
System::EventArgs^ e)
...
NumericUpDown - coding
• As always, we can change anything at runtime

private: System::Void textBox1_TextChanged(System::...
NumericUpDown - coding
• As always, we can change anything at runtime
private: System::Void textBox1_TextChanged(System::O...
NumericUpDown - coding
• As always, we can change anything at runtime

private: System::Void textBox1_TextChanged(System::...
PictureBox
PictureBox
• Very important for drawing!
PictureBox
PictureBox
PictureBox
PictureBox
PictureBox
PictureBox .gif
That’s it for today!
Upcoming SlideShare
Loading in...5
×

C++ Windows Forms L03 - Controls P2

416

Published on

C++ Windows Forms L03 - Controls P2 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
416
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
41
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

C++ Windows Forms L03 - Controls P2

  1. 1. C++.NET Windows Forms Course L03 – Controls Part 2 Mohammad Shaker mohammadshakergtr.wordpress.com C++.NET Windows Forms Course @ZGTRShaker
  2. 2. Switching Between Forms
  3. 3. It’s another form..
  4. 4. Switching between forms
  5. 5. Switching to a another forms • Let’s consider that we want to have two forms and we want to switch between them – #1: First of all we add a new “second” form to out project • Add > new item > form – #2: include its header in first form header file – ( “Form1.h” file ) #include "Form2.h" – #3: pointing to the other form Form2 ^f= gcnew Form2; – #4: and start playing with it :D f->Show();
  6. 6. Switching Back to Form1 • In “Form2.h” namespace MyTestPro { ref class Form1; public: Form1 ^FPtr; Form2(Form1 ^f) { InitializeComponent(); FPtr= f; }
  7. 7. Switching Back to Form1 • In “Form2.cpp” #include "StdAfx.h" #include "Form2.h" #include "Form1.h” namespace MyTestPro { System::Void Form2::Form2_Load(System::Object^ System::EventArgs^ e) { FPtr->Text= “New Form1 Text!"; } } sender,
  8. 8. Peak on Drawing Class Point & Size
  9. 9. Peak on Drawing::Point • What will happen now? private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { button1->Location= 30,120; }
  10. 10. Peak on Drawing::Point
  11. 11. Peak on Drawing::Point • What will happen now? private: System::Void button1_Click(System::Object^ System::EventArgs^ e) { Drawing::Point P; P.X= 2; P.Y= 23; button1->Location= P; } sender,
  12. 12. Drawing::Point
  13. 13. Helpers
  14. 14. Helpers So, what should we do?
  15. 15. Point and Size • Can we do this? Yes! private: System::Void button1_Click_1(System::Object^ System::EventArgs^ e) { Drawing::Size S; S.Height= 200; S.Width= 300; this->Size= S; } sender,
  16. 16. Point and Size • Can we do this? private: System::Void button1_Click_1(System::Object^ System::EventArgs^ e) { Drawing::Size ^S; S->Height= 200; S->Width= 300; this->Size= S; } sender, Compile error Error 1 error C2664: 'void System::Windows::Forms::Control::Size::set(System::Drawing::Size)': cannot convert parameter 1 from 'System::Drawing::Size ^' to 'System::Drawing::Size' c:userszgtrdocumentsvisual studio 2008projectsdotnet4dotnet4Form1.h 129 dotNet4
  17. 17. Helpers
  18. 18. Point and Size private: System::Void button1_Click_1(System::Object^ sender, System::EventArgs^ e) { this->Size= Drawing::Size(200,300); } Works!
  19. 19. Helpers
  20. 20. Point and Size
  21. 21. Label
  22. 22. Label • Properties: Name, Text, Font, image, Location, Size, TabStop, TabIndex, Visible, BackColor • Event: MouseClick, MouseDown, MouseLeave, Resize, SizeChange, TextChanged, VisibleChanged, KeyUp, KeyDown, DragDrop
  23. 23. TextBox
  24. 24. TextBox • Properties: Name, Text, Font, image, Location, Size, TabStop, TabIndex, Visible, BackColor, MultiLine, ScrollBar • Event: MouseClick, MouseDown, MouseLeave, Resize, SizeChange, TextChanged, VisibleChanged, KeyUp, KeyDown, DragDrop
  25. 25. Panel
  26. 26. Panel • Properties: Name, Text, Font, image, Location, Size, TabStop, TabIndex, Visible, BackColor, Border Style, AutoSize • Event: MouseClick, MouseDown, MouseLeave, Resize, SizeChange, TextChanged, VisibleChanged, KeyUp, KeyDown, DragDrop
  27. 27. TrackBar
  28. 28. TrackBar
  29. 29. TrackBar
  30. 30. TrackBar Keyboard keys (Arrows) Number of ticks between tick marks position
  31. 31. TrackBar • What will happen now? private: System::Void trackBar1_Scroll(System::Object^ System::EventArgs^ e) { textBox1->Text= trackBar1->Value.ToString(); } sender,
  32. 32. TrackBar
  33. 33. ProgressBar
  34. 34. ProgressBar
  35. 35. ProgressBar
  36. 36. ProgressBar
  37. 37. ProgressBar • Increment the progressBar and perform the “performStep()” • What will happen when pressing the button? private: System::Void button1_Click_4(System::Object^ System::EventArgs^ e) { progressBar1->PerformStep(); } sender,
  38. 38. ProgressBar • What will happen now when pressing the button, repeatedly? private: System::Void button1_Click_4(System::Object^ sender, System::EventArgs^ e) { progressBar1->PerformStep(); textBox1->Text= progressBar1->Value.ToString(); }
  39. 39. ProgressBar Before clicking button1 After clicking button1 for 1st time After clicking button1 for 2nd time
  40. 40. ProgressBar • Another example: – The following code example uses a ProgressBar control to display the progress of a file copy operation. The example uses the Minimum and Maximum properties to specify a range for the ProgressBar that is equivalent to the number of files to copy. The code also uses the Step property with the PerformStep method to increment the value of theProgressBar as a file is copied. This example requires that you have a ProgressBar control created called pBar1 that is created within a Form and that there is a method created called CopyFile (that returns a Boolean value indicating the file copy operation was completed successfully) that performs the file copy operation. The code also requires that an array of strings containing the files to copy is created and passed to the CopyWithProgress method defined in the example and that the method is called from another method or event in the Form.
  41. 41. private: void CopyWithProgress( array<String^>^filenames ) { // Display the ProgressBar control. pBar1->Visible= true; // Set Minimum to 1 to represent the first file being copied. pBar1->Minimum= 1; // Set Maximum to the total number of files to copy. pBar1->Maximum= filenames->Length; // Set the initial value of the ProgressBar. pBar1->Value= 1; // Set the Step property to a value of 1 to represent each file being copied. pBar1->Step= 1; // Loop through all files to copy. for ( int x= 1; x <= filenames->Length; x++ ) { // Copy the file and increment the ProgressBar if successful. if ( CopyFile( filenames[ x - 1 ] )== true ) { // Perform the increment on the ProgressBar. pBar1->PerformStep(); } } }
  42. 42. NumericUpDown
  43. 43. NumericUpDown properties The interval Starting value
  44. 44. NumericUpDown - coding • Text property private: System::Void button1_Click_1(System::Object^ System::EventArgs^ e) { textBox1->Text= numericUpDown1->Text; } sender,
  45. 45. NumericUpDown - coding • Everything ok? private: System::Void textBox1_TextChanged(System::Object^ System::EventArgs^ e) { numericUpDown1->Value= textBox1->Text; } Compiler error. String assigned to int sender,
  46. 46. NumericUpDown - coding • As always, we can change anything at runtime private: System::Void textBox1_TextChanged(System::Object^ System::EventArgs^ e) { numericUpDown1->Value= } int::Parse(textBox1->Text); sender,
  47. 47. NumericUpDown - coding • As always, we can change anything at runtime private: System::Void textBox1_TextChanged(System::Object^ System::EventArgs^ e) sender, { int i =int::TryParse(textBox1->Text, numericUpDown1->Value); }
  48. 48. NumericUpDown - coding • As always, we can change anything at runtime private: System::Void textBox1_TextChanged(System::Object^ System::EventArgs^ e) { numericUpDown1->Text= } textBox1->Text; sender,
  49. 49. PictureBox
  50. 50. PictureBox • Very important for drawing!
  51. 51. PictureBox
  52. 52. PictureBox
  53. 53. PictureBox
  54. 54. PictureBox
  55. 55. PictureBox
  56. 56. PictureBox .gif
  57. 57. That’s it for today!
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×