SlideShare a Scribd company logo
C++.NET
Windows Forms Course
L03 – Controls Part 2

Mohammad Shaker
mohammadshakergtr.wordpress.com
C++.NET Windows Forms Course
@ZGTRShaker
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: 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();
Switching Back to Form1
• In “Form2.h”
namespace MyTestPro {
ref class Form1;
public: Form1 ^FPtr;
Form2(Form1 ^f)
{
InitializeComponent();
FPtr= f;
}
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,
Peak on Drawing Class
Point & Size
Peak on Drawing::Point
• What will happen now?

private: System::Void button1_Click(System::Object^
sender, System::EventArgs^ e)
{
button1->Location= 30,120;
}
Peak on Drawing::Point
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,
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)
{
Drawing::Size S;
S.Height= 200;
S.Width= 300;
this->Size= S;
}

sender,
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
Helpers
Point and Size
private: System::Void button1_Click_1(System::Object^
sender, System::EventArgs^ e)
{
this->Size= Drawing::Size(200,300);
}
Works!
Helpers
Point and Size
Label
Label
• Properties:
Name, Text, Font, image, Location, Size, TabStop, TabIndex,
Visible, BackColor

• Event:
MouseClick, MouseDown, MouseLeave, Resize, SizeChange,
TextChanged, VisibleChanged, KeyUp, KeyDown, DragDrop
TextBox
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
Panel
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
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->Text= trackBar1->Value.ToString();
}

sender,
TrackBar
ProgressBar
ProgressBar
ProgressBar
ProgressBar
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,
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();
}
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 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.
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();
}
}
}
NumericUpDown
NumericUpDown properties
The interval

Starting value
NumericUpDown - coding
• Text property
private: System::Void button1_Click_1(System::Object^
System::EventArgs^ e)
{
textBox1->Text= numericUpDown1->Text;
}

sender,
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,
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,
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);
}
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,
PictureBox
PictureBox
• Very important for drawing!
PictureBox
PictureBox
PictureBox
PictureBox
PictureBox
PictureBox .gif
That’s it for today!

More Related Content

PDF
C++ Windows Forms L02 - Controls P1
PDF
C++ Windows Forms L06 - Utlitity and Strings
PDF
C++ Windows Forms L11 - Inheritance
PDF
C++ Windows Forms L04 - Controls P3
PDF
C++ Windows Forms L09 - GDI P2
PDF
C++ Windows Forms L05 - Controls P4
PDF
C++ Windows Forms L10 - Instantiate
PDF
C++ Windows Forms L07 - Collections
C++ Windows Forms L02 - Controls P1
C++ Windows Forms L06 - Utlitity and Strings
C++ Windows Forms L11 - Inheritance
C++ Windows Forms L04 - Controls P3
C++ Windows Forms L09 - GDI P2
C++ Windows Forms L05 - Controls P4
C++ Windows Forms L10 - Instantiate
C++ Windows Forms L07 - Collections

What's hot (20)

PPT
VB Dot net
DOCX
.net progrmming part4
PDF
The Ring programming language version 1.8 book - Part 7 of 202
DOCX
C# labprograms
PDF
The Ring programming language version 1.5.2 book - Part 7 of 181
DOCX
C# console programms
PDF
The Ring programming language version 1.3 book - Part 83 of 88
PDF
PDF
Exploring Clojurescript
PDF
The Ring programming language version 1.5.1 book - Part 6 of 180
PDF
Inventory management
PDF
The Ring programming language version 1.5.3 book - Part 7 of 184
PDF
Calculator code
PDF
The Ring programming language version 1.7 book - Part 7 of 196
DOCX
Ete programs
PPTX
Poor Man's Functional Programming
PPTX
Python 3.6 Features 20161207
PDF
Refactoring to Macros with Clojure
PDF
The Ring programming language version 1.5.1 book - Part 13 of 180
PDF
DOM-based Test Adequacy Criteria for Web Applications
VB Dot net
.net progrmming part4
The Ring programming language version 1.8 book - Part 7 of 202
C# labprograms
The Ring programming language version 1.5.2 book - Part 7 of 181
C# console programms
The Ring programming language version 1.3 book - Part 83 of 88
Exploring Clojurescript
The Ring programming language version 1.5.1 book - Part 6 of 180
Inventory management
The Ring programming language version 1.5.3 book - Part 7 of 184
Calculator code
The Ring programming language version 1.7 book - Part 7 of 196
Ete programs
Poor Man's Functional Programming
Python 3.6 Features 20161207
Refactoring to Macros with Clojure
The Ring programming language version 1.5.1 book - Part 13 of 180
DOM-based Test Adequacy Criteria for Web Applications
Ad

Similar to C++ Windows Forms L03 - Controls P2 (20)

PPTX
Vs c# lecture1
PPT
PPTX
Controls events
PPT
4.7.14&amp;17.7.14&amp;23.6.15&amp;10.9.15
PPTX
Windows form application - C# Training
PDF
PPT
06 win forms
DOC
Practicalfileofvb workshop
PDF
Lab1
DOCX
The visual studio start page is shown in the figure below
PPS
02 gui 02
PPT
visual programming GDI presentation powerpoint
PPT
Visual programming Chapter 3: GUI (Graphical User Interface)
PPTX
ch 3 of C# programming in advanced programming
PDF
Visualbasic tutorial
DOC
9b4c1 vb(pd)
DOC
9b4c1 vb(pd) (2)
PPSX
PDF
Visual Basic IDE Introduction
PDF
Visual Basic IDE Intro.pdf
Vs c# lecture1
Controls events
4.7.14&amp;17.7.14&amp;23.6.15&amp;10.9.15
Windows form application - C# Training
06 win forms
Practicalfileofvb workshop
Lab1
The visual studio start page is shown in the figure below
02 gui 02
visual programming GDI presentation powerpoint
Visual programming Chapter 3: GUI (Graphical User Interface)
ch 3 of C# programming in advanced programming
Visualbasic tutorial
9b4c1 vb(pd)
9b4c1 vb(pd) (2)
Visual Basic IDE Introduction
Visual Basic IDE Intro.pdf
Ad

More from Mohammad Shaker (20)

PDF
12 Rules You Should to Know as a Syrian Graduate
PDF
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
PDF
Interaction Design L06 - Tricks with Psychology
PDF
Short, Matters, Love - Passioneers Event 2015
PDF
Unity L01 - Game Development
PDF
Android L07 - Touch, Screen and Wearables
PDF
Interaction Design L03 - Color
PDF
Interaction Design L05 - Typography
PDF
Interaction Design L04 - Materialise and Coupling
PDF
Android L05 - Storage
PDF
Android L04 - Notifications and Threading
PDF
Android L09 - Windows Phone and iOS
PDF
Interaction Design L01 - Mobile Constraints
PDF
Interaction Design L02 - Pragnanz and Grids
PDF
Android L10 - Stores and Gaming
PDF
Android L06 - Cloud / Parse
PDF
Android L08 - Google Maps and Utilities
PDF
Android L03 - Styles and Themes
PDF
Android L02 - Activities and Adapters
PDF
Android L01 - Warm Up
12 Rules You Should to Know as a Syrian Graduate
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Interaction Design L06 - Tricks with Psychology
Short, Matters, Love - Passioneers Event 2015
Unity L01 - Game Development
Android L07 - Touch, Screen and Wearables
Interaction Design L03 - Color
Interaction Design L05 - Typography
Interaction Design L04 - Materialise and Coupling
Android L05 - Storage
Android L04 - Notifications and Threading
Android L09 - Windows Phone and iOS
Interaction Design L01 - Mobile Constraints
Interaction Design L02 - Pragnanz and Grids
Android L10 - Stores and Gaming
Android L06 - Cloud / Parse
Android L08 - Google Maps and Utilities
Android L03 - Styles and Themes
Android L02 - Activities and Adapters
Android L01 - Warm Up

Recently uploaded (20)

PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Empathic Computing: Creating Shared Understanding
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Machine learning based COVID-19 study performance prediction
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Big Data Technologies - Introduction.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
Cloud computing and distributed systems.
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
Network Security Unit 5.pdf for BCA BBA.
Empathic Computing: Creating Shared Understanding
“AI and Expert System Decision Support & Business Intelligence Systems”
Machine learning based COVID-19 study performance prediction
Review of recent advances in non-invasive hemoglobin estimation
Digital-Transformation-Roadmap-for-Companies.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Big Data Technologies - Introduction.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
MYSQL Presentation for SQL database connectivity
Advanced methodologies resolving dimensionality complications for autism neur...
Per capita expenditure prediction using model stacking based on satellite ima...
Assigned Numbers - 2025 - Bluetooth® Document
Cloud computing and distributed systems.
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing

C++ Windows Forms L03 - Controls P2

  • 1. C++.NET Windows Forms Course L03 – Controls Part 2 Mohammad Shaker mohammadshakergtr.wordpress.com C++.NET Windows Forms Course @ZGTRShaker
  • 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. Switching Back to Form1 • In “Form2.h” namespace MyTestPro { ref class Form1; public: Form1 ^FPtr; Form2(Form1 ^f) { InitializeComponent(); FPtr= f; }
  • 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. Peak on Drawing Class Point & Size
  • 9. Peak on Drawing::Point • What will happen now? private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { button1->Location= 30,120; }
  • 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,
  • 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. 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
  • 18. Point and Size private: System::Void button1_Click_1(System::Object^ sender, System::EventArgs^ e) { this->Size= Drawing::Size(200,300); } Works!
  • 21. Label
  • 22. Label • Properties: Name, Text, Font, image, Location, Size, TabStop, TabIndex, Visible, BackColor • Event: MouseClick, MouseDown, MouseLeave, Resize, SizeChange, TextChanged, VisibleChanged, KeyUp, KeyDown, DragDrop
  • 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. Panel
  • 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
  • 30. TrackBar Keyboard keys (Arrows) Number of ticks between tick marks position
  • 31. TrackBar • What will happen now? private: System::Void trackBar1_Scroll(System::Object^ System::EventArgs^ e) { textBox1->Text= trackBar1->Value.ToString(); } sender,
  • 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. 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. ProgressBar Before clicking button1 After clicking button1 for 1st time After clicking button1 for 2nd time
  • 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. 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(); } } }
  • 44. NumericUpDown - coding • Text property private: System::Void button1_Click_1(System::Object^ System::EventArgs^ e) { textBox1->Text= numericUpDown1->Text; } sender,
  • 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. 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. 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. 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,
  • 57. That’s it for today!