SlideShare ist ein Scribd-Unternehmen logo
1 von 71
Downloaden Sie, um offline zu lesen
C++.NET
Windows Forms Course
L02 – Controls Part 1

Mohammad Shaker
mohammadshakergtr.wordpress.com
C++.NET Windows Forms Course
@ZGTRShaker
Controls
•
•
•
•
•
•
•
•

Form
Button
CheckBox
CheckedListBox
ComboBox
Label
ListBox
PictureBox

•
•
•
•
•
•
•

ProgressBar
RadioButton
TextBox
Panel
TabControl
DataGridView
Timer
Windows Forms
Form’s Properties
Form’s Events

The Form is selected
Control Properties and Events
• Applications :
– Design Time VS runtime

• Controls :
– Properties
• Width , color .. etc

– Events
• MouseClick , MouseHover , DragDrop .. etc
Your First Form: Form1
Form’s Properties
– Properties :
•
•
•
•
•
•
•

BackColor
AutoSize
Font
Location
Opacity
Size (width , Height )
Text
Form’s Events
– Event :
•
•
•
•
•
•
•
•
•

Load
Click
KeyUp  down  ….
MouseOver  Down  leave  …
ResizeBegin  End
TextChange
Validation
FormClosing
Form Closed

(imp.)
Form at Design Time
With Form1 being selected
Form at Design Time
With Form1 being selected
.ico extension
Forms Live Testing
Changing Properties at runtime through Events
Button
23
Button
– Properties :

– Name , Text , Font , image , Location , Size , TabStop , TabIndex ,
Visible , BackColor
– Event :

– MouseClick , MouseDown , MouseLeave , Resize , SizeChange ,
TextChanged , VisibleChanged , KeyUp , KeyDown , DragDrop
Changing properties at runtime
• Considering we have the following design (at design time)
Changing properties at runtime
• Adding the following button event

private: System::Void button1_Click(System::Object^
sender, System::EventArgs^ e)
{
button1 -> Text="I'm button1!!";
}

Control

Property

Valid value
Changing properties at runtime
• Adding the following button event

private: System::Void button1_Click(System::Object^
sender, System::EventArgs^ e)
{
button1 -> Text="I'm button1!!";
}

Object (intsance)
Reference button by
its name

Data Member

Valid value
Changing properties at runtime

After clicking the button
Changing properties at runtime

private: System::Void button1_Click(System::Object^
sender, System::EventArgs^ e)
{
Form1 -> Text=" Hello World ”;
}

Member

Valid value
Changing properties at runtime

private: System::Void button1_Click(System::Object^
sender, System::EventArgs^ e)
{
Form1 -> Text=" Hello World ”;
}

Member

Valid value
Changing properties at runtime
• Now , let’s change the “Form”’s Text property .

private: System::Void button1_Click(System::Object^
sender, System::EventArgs^ e)
{
Form1 -> Text=" Hello World ”;
}

Member

Valid value
Changing properties at runtime

private: System::Void button1_Click(System::Object^
sender, System::EventArgs^ e)
{
this -> Text="Hello World";
}

Object at runtime
(reference to Form1)
Since we are inside
the Form1 class

Member

Value
Changing properties at runtime

After Clicking the Button
Changing properties at runtime
• Now , let’s change the “Form”’s Opacity property .

private: System::Void button1_Click(System::Object^
sender, System::EventArgs^ e)
{
this -> Opacity=20;
}

Class

Member

Valid value
Changing properties at runtime
• Now , let’s change the “Form”’s Opacity property .

private: System::Void button1_Click(System::Object^
sender, System::EventArgs^ e)
{
this -> Opacity=20;
}

Class

Member

Valid value
Changing properties at runtime
• Now , let’s change the “Form”’s Opacity property .

private: System::Void button1_Click(System::Object^
sender, System::EventArgs^ e)
{
this -> Opacity=0.2;
}

Class

Member

Valid value
Changing properties at runtime

After Clicking the Button
Message Box
MessageBox
private: System::Void button1_Click(System::Object^
sender, System::EventArgs^ e)
{
MessageBox::Show("Hello!!!");
}
Let the .NET write for you.
Intellisense is ready to help you!
(Problem in 2010 and afterward)
21 Overload!
Form
Hide() vs Close()
Form Hide() vs Close()
What’s the difference between these two:

private: System::Void button1_Click(System::Object^
System::EventArgs^ e)
{
this->Hide();
}

sender,

private: System::Void button1_Click(System::Object^
System::EventArgs^ e)
{
this->Close();
}

sender,
Form – Hide problem!
Consider that we have only one form and we write the
following code:
private: System::Void Form1_Load(System::Object^
sender, System::EventArgs^ e)
{
this->Hide();
}

The form won’t be hidden on loading!
Form – Hide problem!
What happens now when breaking the project and run it again?

private: System::Void button1_Click(System::Object^
sender, System::EventArgs^ e)
{
this->Hide();
}

It won’t compile! When hiding the form , the project is still processed!!!
So we should terminate its process first from task manager
Opacity Problem , too!
The applications are hidden but
not closed. All the memory
allocated by each hidden
application is still there
Application class
Application class
• Hierarchy :
– System.Windows.Forms

• Methods :
– Run
– Exit
Application class – Exit Method
• Informs all message pumps that they must terminate, and
then closes all application windows after the messages have
been processed.
Application::Exit();
Application class – Exit Method
• What will happen now?
The whole application (with all forms) will simply close and
the resources will be freed.
private: System::Void Form1_Load(System::Object^
System::EventArgs^ e)
{
Application::Exit();
}

sender,
Exit() vs Close()
• What’s the difference?
Application::Exit();
this->Close();
Managed vs Un-Managed
CODE
Managed VS Un-Managed
• Usually …
– Managed : .NET
– Un-Managed : C++

• gcnew
– Garbage collector
Managed VS Un-Managed
• Usually …
– Managed : .NET
– Un-Managed : C++

• gcnew
– Garbage collector
Managed VS Un-Managed
• Stack  heap “Un-Managed heap”  managed heap
int MyVar=10;

 stack

int *Ptr=new int;

 Un-Managed heap

int ^Ptr=gcnew int;  managed heap

• What’s the problem then?!!
Managed VS Un-Managed
• Let’s have the following, anything wrong?

int *Ptr=new int;
Ptr=NULL;

 Un-Managed heap

It’s a leaking in memory!

int ^Ptr=gcnew int;  managed heap
Ptr=NULL;
Not a leak anymore!
Managed VS Un-Managed
• Let’s have the following, anything wrong?
int *Ptr=new int;
Ptr=NULL;

 Un-Managed heap

It’s a leaking in memory!

int ^Ptr=gcnew int;  managed heap
Ptr=NULL;
Not a leak anymore!
Which one of these works?
private: System::Void button1_Click_1(System::Object^ sender,
System::EventArgs^ e)
{
Drawing::Size *S;
S->Height=200;
S->Width=300;
this->Size=*S;
}
there’s no new  unmanaged
private: System::Void button1_Click_1(System::Object^ sender,
System::EventArgs^ e)
{
Drawing::Size *S=gcnew Drawing::Size;
S->Height=200;
S->Width=300;
this->Size=*S;
gcnew with *  unmanaged with managed
}
private: System::Void button1_Click_1(System::Object^ sender,
System::EventArgs^ e)
{
Drawing::Size *S=new Drawing::Size;
S->Height=200;
S->Width=300;
this->Size=*S;
WORKS!  unmanaged
}
Which one of these works?
private: System::Void button1_Click_1(System::Object^ sender,
System::EventArgs^ e)
{
Drawing::Size *S=new Size;
S->Height=200;
S->Width=300;
this->Size=*S;
Un-Known Size identifier “3’laza :D”
}
private: System::Void button1_Click_1(System::Object^ sender,
System::EventArgs^ e)
{
Drawing::Size ^S=gcnew Drawing::Size;
S->Height=200;
S->Width=300;
this->Size=*S;
}
Works!  managed
private: System::Void button1_Click_1(System::Object^ sender,
System::EventArgs^ e)
{
Drawing::Size ^S=gcnew Drawing::Size;
S->Height=200;
S->Width=300;
this->Size=^S;
}
Compiler error .. No such
Which one of these works?
private: System::Void button1_Click_1(System::Object^
System::EventArgs^ e)
{
Drawing::Size ^S;
S->Height=200;
S->Width=300;
this->S=^S;
}
Error .. ^

sender,

private: System::Void button1_Click_1(System::Object^ sender,
System::EventArgs^ e)
{
Drawing::Size ^S=new Drawing::Size;
S->Height=200;
S->Width=300;
this->Size=^S;
}
Should be gcnew , not new
Which one of these works?

private: System::Void button1_Click_1(System::Object^
sender, System::EventArgs^ e)
{
this->Size=Drawing::Size(200,300);
}
Works!
Which one of these works?

private: System::Void button1_Click_1(System::Object^
sender, System::EventArgs^ e)
{
this->Size=Drawing::Size(200,300);
}
Works!
References
msdn Awesome library
C++ , C# , VB.NET , ASP.NET , XNA , XML ... etc
http://msdn.microsoft.com/en-us/library/default.aspx
That’s it for today!

Weitere ähnliche Inhalte

Was ist angesagt?

DOM-based Test Adequacy Criteria for Web Applications
DOM-based Test Adequacy Criteria for Web ApplicationsDOM-based Test Adequacy Criteria for Web Applications
DOM-based Test Adequacy Criteria for Web Applications
SALT Lab @ UBC
 
Noguera jesus
Noguera jesusNoguera jesus
Noguera jesus
gabo2200
 
Java programs
Java programsJava programs
Java programs
jojeph
 
Aplikasi rawat-inap-vbnet
Aplikasi rawat-inap-vbnetAplikasi rawat-inap-vbnet
Aplikasi rawat-inap-vbnet
Diaz Alfahrezy
 
Poor Man's Functional Programming
Poor Man's Functional ProgrammingPoor Man's Functional Programming
Poor Man's Functional Programming
Dmitry Buzdin
 
C# Delegates, Events, Lambda
C# Delegates, Events, LambdaC# Delegates, Events, Lambda
C# Delegates, Events, Lambda
Jussi Pohjolainen
 

Was ist angesagt? (20)

C++ Windows Forms L08 - GDI P1
C++ Windows Forms L08 - GDI P1 C++ Windows Forms L08 - GDI P1
C++ Windows Forms L08 - GDI P1
 
.net progrmming part4
.net progrmming part4.net progrmming part4
.net progrmming part4
 
The Ring programming language version 1.8 book - Part 7 of 202
The Ring programming language version 1.8 book - Part 7 of 202The Ring programming language version 1.8 book - Part 7 of 202
The Ring programming language version 1.8 book - Part 7 of 202
 
Bot builder v4 HOL
Bot builder v4 HOLBot builder v4 HOL
Bot builder v4 HOL
 
Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.
 
The Ring programming language version 1.5.2 book - Part 7 of 181
The Ring programming language version 1.5.2 book - Part 7 of 181The Ring programming language version 1.5.2 book - Part 7 of 181
The Ring programming language version 1.5.2 book - Part 7 of 181
 
VB Dot net
VB Dot net VB Dot net
VB Dot net
 
Chat Room System using Java Swing
Chat Room System using Java SwingChat Room System using Java Swing
Chat Room System using Java Swing
 
The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88
 
C# Starter L07-Objects Cloning
C# Starter L07-Objects CloningC# Starter L07-Objects Cloning
C# Starter L07-Objects Cloning
 
The Ring programming language version 1.5.1 book - Part 6 of 180
The Ring programming language version 1.5.1 book - Part 6 of 180The Ring programming language version 1.5.1 book - Part 6 of 180
The Ring programming language version 1.5.1 book - Part 6 of 180
 
The Ring programming language version 1.5.3 book - Part 7 of 184
The Ring programming language version 1.5.3 book - Part 7 of 184The Ring programming language version 1.5.3 book - Part 7 of 184
The Ring programming language version 1.5.3 book - Part 7 of 184
 
DOM-based Test Adequacy Criteria for Web Applications
DOM-based Test Adequacy Criteria for Web ApplicationsDOM-based Test Adequacy Criteria for Web Applications
DOM-based Test Adequacy Criteria for Web Applications
 
Noguera jesus
Noguera jesusNoguera jesus
Noguera jesus
 
The Ring programming language version 1.5.4 book - Part 7 of 185
The Ring programming language version 1.5.4 book - Part 7 of 185The Ring programming language version 1.5.4 book - Part 7 of 185
The Ring programming language version 1.5.4 book - Part 7 of 185
 
Java programs
Java programsJava programs
Java programs
 
Aplikasi rawat-inap-vbnet
Aplikasi rawat-inap-vbnetAplikasi rawat-inap-vbnet
Aplikasi rawat-inap-vbnet
 
The Ring programming language version 1.7 book - Part 7 of 196
The Ring programming language version 1.7 book - Part 7 of 196The Ring programming language version 1.7 book - Part 7 of 196
The Ring programming language version 1.7 book - Part 7 of 196
 
Poor Man's Functional Programming
Poor Man's Functional ProgrammingPoor Man's Functional Programming
Poor Man's Functional Programming
 
C# Delegates, Events, Lambda
C# Delegates, Events, LambdaC# Delegates, Events, Lambda
C# Delegates, Events, Lambda
 

Ähnlich wie C++ Windows Forms L02 - Controls P1

Understanding JavaScript Event-based Interactions
Understanding JavaScript Event-based InteractionsUnderstanding JavaScript Event-based Interactions
Understanding JavaScript Event-based Interactions
SALT Lab @ UBC
 
12 High Level UI Event Handling
12 High Level UI Event Handling12 High Level UI Event Handling
12 High Level UI Event Handling
corneliuskoo
 

Ähnlich wie C++ Windows Forms L02 - Controls P1 (20)

cse581_03_EventProgramming.ppt
cse581_03_EventProgramming.pptcse581_03_EventProgramming.ppt
cse581_03_EventProgramming.ppt
 
44c
44c44c
44c
 
2006 - Basta!: Advanced server controls
2006 - Basta!: Advanced server controls2006 - Basta!: Advanced server controls
2006 - Basta!: Advanced server controls
 
BSides MCR 2016: From CSV to CMD to qwerty
BSides MCR 2016: From CSV to CMD to qwertyBSides MCR 2016: From CSV to CMD to qwerty
BSides MCR 2016: From CSV to CMD to qwerty
 
06 win forms
06 win forms06 win forms
06 win forms
 
Understanding JavaScript Event-based Interactions
Understanding JavaScript Event-based InteractionsUnderstanding JavaScript Event-based Interactions
Understanding JavaScript Event-based Interactions
 
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
 
35c
35c35c
35c
 
GDC 2010 - A Dynamic Component Architecture for High Performance Gameplay - M...
GDC 2010 - A Dynamic Component Architecture for High Performance Gameplay - M...GDC 2010 - A Dynamic Component Architecture for High Performance Gameplay - M...
GDC 2010 - A Dynamic Component Architecture for High Performance Gameplay - M...
 
Junit in mule
Junit in muleJunit in mule
Junit in mule
 
Junit in mule
Junit in muleJunit in mule
Junit in mule
 
Junit in mule
Junit in muleJunit in mule
Junit in mule
 
Junit in mule demo
Junit in mule demo Junit in mule demo
Junit in mule demo
 
17javascript.ppt
17javascript.ppt17javascript.ppt
17javascript.ppt
 
17javascript.ppt
17javascript.ppt17javascript.ppt
17javascript.ppt
 
CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32
 
Session 5#
Session 5#Session 5#
Session 5#
 
Masterin Large Scale Java Script Applications
Masterin Large Scale Java Script ApplicationsMasterin Large Scale Java Script Applications
Masterin Large Scale Java Script Applications
 
javascript Event Handling and introduction to event.ppt
javascript Event Handling and introduction to event.pptjavascript Event Handling and introduction to event.ppt
javascript Event Handling and introduction to event.ppt
 
12 High Level UI Event Handling
12 High Level UI Event Handling12 High Level UI Event Handling
12 High Level UI Event Handling
 

Mehr von Mohammad Shaker

Mehr von Mohammad Shaker (20)

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

Kürzlich hochgeladen

Kürzlich hochgeladen (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

C++ Windows Forms L02 - Controls P1

  • 1. C++.NET Windows Forms Course L02 – Controls Part 1 Mohammad Shaker mohammadshakergtr.wordpress.com C++.NET Windows Forms Course @ZGTRShaker
  • 2.
  • 4.
  • 5.
  • 6.
  • 7.
  • 10.
  • 11. Control Properties and Events • Applications : – Design Time VS runtime • Controls : – Properties • Width , color .. etc – Events • MouseClick , MouseHover , DragDrop .. etc
  • 13. Form’s Properties – Properties : • • • • • • • BackColor AutoSize Font Location Opacity Size (width , Height ) Text
  • 14. Form’s Events – Event : • • • • • • • • • Load Click KeyUp down …. MouseOver Down leave … ResizeBegin End TextChange Validation FormClosing Form Closed (imp.)
  • 15. Form at Design Time With Form1 being selected
  • 16. Form at Design Time With Form1 being selected
  • 18.
  • 19.
  • 20. Forms Live Testing Changing Properties at runtime through Events
  • 22.
  • 23. 23
  • 24.
  • 25. Button – Properties : – Name , Text , Font , image , Location , Size , TabStop , TabIndex , Visible , BackColor – Event : – MouseClick , MouseDown , MouseLeave , Resize , SizeChange , TextChanged , VisibleChanged , KeyUp , KeyDown , DragDrop
  • 26. Changing properties at runtime • Considering we have the following design (at design time)
  • 27. Changing properties at runtime • Adding the following button event private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { button1 -> Text="I'm button1!!"; } Control Property Valid value
  • 28. Changing properties at runtime • Adding the following button event private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { button1 -> Text="I'm button1!!"; } Object (intsance) Reference button by its name Data Member Valid value
  • 29. Changing properties at runtime After clicking the button
  • 30. Changing properties at runtime private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { Form1 -> Text=" Hello World ”; } Member Valid value
  • 31. Changing properties at runtime private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { Form1 -> Text=" Hello World ”; } Member Valid value
  • 32. Changing properties at runtime • Now , let’s change the “Form”’s Text property . private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { Form1 -> Text=" Hello World ”; } Member Valid value
  • 33. Changing properties at runtime private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { this -> Text="Hello World"; } Object at runtime (reference to Form1) Since we are inside the Form1 class Member Value
  • 34. Changing properties at runtime After Clicking the Button
  • 35. Changing properties at runtime • Now , let’s change the “Form”’s Opacity property . private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { this -> Opacity=20; } Class Member Valid value
  • 36. Changing properties at runtime • Now , let’s change the “Form”’s Opacity property . private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { this -> Opacity=20; } Class Member Valid value
  • 37. Changing properties at runtime • Now , let’s change the “Form”’s Opacity property . private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { this -> Opacity=0.2; } Class Member Valid value
  • 38. Changing properties at runtime After Clicking the Button
  • 40. MessageBox private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { MessageBox::Show("Hello!!!"); }
  • 41. Let the .NET write for you. Intellisense is ready to help you! (Problem in 2010 and afterward)
  • 42.
  • 43.
  • 44.
  • 45.
  • 48. Form Hide() vs Close() What’s the difference between these two: private: System::Void button1_Click(System::Object^ System::EventArgs^ e) { this->Hide(); } sender, private: System::Void button1_Click(System::Object^ System::EventArgs^ e) { this->Close(); } sender,
  • 49. Form – Hide problem! Consider that we have only one form and we write the following code: private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { this->Hide(); } The form won’t be hidden on loading!
  • 50. Form – Hide problem! What happens now when breaking the project and run it again? private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { this->Hide(); } It won’t compile! When hiding the form , the project is still processed!!! So we should terminate its process first from task manager
  • 52. The applications are hidden but not closed. All the memory allocated by each hidden application is still there
  • 54. Application class • Hierarchy : – System.Windows.Forms • Methods : – Run – Exit
  • 55.
  • 56. Application class – Exit Method • Informs all message pumps that they must terminate, and then closes all application windows after the messages have been processed. Application::Exit();
  • 57. Application class – Exit Method • What will happen now? The whole application (with all forms) will simply close and the resources will be freed. private: System::Void Form1_Load(System::Object^ System::EventArgs^ e) { Application::Exit(); } sender,
  • 58. Exit() vs Close() • What’s the difference? Application::Exit(); this->Close();
  • 60. Managed VS Un-Managed • Usually … – Managed : .NET – Un-Managed : C++ • gcnew – Garbage collector
  • 61. Managed VS Un-Managed • Usually … – Managed : .NET – Un-Managed : C++ • gcnew – Garbage collector
  • 62. Managed VS Un-Managed • Stack heap “Un-Managed heap” managed heap int MyVar=10; stack int *Ptr=new int; Un-Managed heap int ^Ptr=gcnew int; managed heap • What’s the problem then?!!
  • 63. Managed VS Un-Managed • Let’s have the following, anything wrong? int *Ptr=new int; Ptr=NULL; Un-Managed heap It’s a leaking in memory! int ^Ptr=gcnew int; managed heap Ptr=NULL; Not a leak anymore!
  • 64. Managed VS Un-Managed • Let’s have the following, anything wrong? int *Ptr=new int; Ptr=NULL; Un-Managed heap It’s a leaking in memory! int ^Ptr=gcnew int; managed heap Ptr=NULL; Not a leak anymore!
  • 65. Which one of these works? private: System::Void button1_Click_1(System::Object^ sender, System::EventArgs^ e) { Drawing::Size *S; S->Height=200; S->Width=300; this->Size=*S; } there’s no new unmanaged private: System::Void button1_Click_1(System::Object^ sender, System::EventArgs^ e) { Drawing::Size *S=gcnew Drawing::Size; S->Height=200; S->Width=300; this->Size=*S; gcnew with * unmanaged with managed } private: System::Void button1_Click_1(System::Object^ sender, System::EventArgs^ e) { Drawing::Size *S=new Drawing::Size; S->Height=200; S->Width=300; this->Size=*S; WORKS! unmanaged }
  • 66. Which one of these works? private: System::Void button1_Click_1(System::Object^ sender, System::EventArgs^ e) { Drawing::Size *S=new Size; S->Height=200; S->Width=300; this->Size=*S; Un-Known Size identifier “3’laza :D” } private: System::Void button1_Click_1(System::Object^ sender, System::EventArgs^ e) { Drawing::Size ^S=gcnew Drawing::Size; S->Height=200; S->Width=300; this->Size=*S; } Works! managed private: System::Void button1_Click_1(System::Object^ sender, System::EventArgs^ e) { Drawing::Size ^S=gcnew Drawing::Size; S->Height=200; S->Width=300; this->Size=^S; } Compiler error .. No such
  • 67. Which one of these works? private: System::Void button1_Click_1(System::Object^ System::EventArgs^ e) { Drawing::Size ^S; S->Height=200; S->Width=300; this->S=^S; } Error .. ^ sender, private: System::Void button1_Click_1(System::Object^ sender, System::EventArgs^ e) { Drawing::Size ^S=new Drawing::Size; S->Height=200; S->Width=300; this->Size=^S; } Should be gcnew , not new
  • 68. Which one of these works? private: System::Void button1_Click_1(System::Object^ sender, System::EventArgs^ e) { this->Size=Drawing::Size(200,300); } Works!
  • 69. Which one of these works? private: System::Void button1_Click_1(System::Object^ sender, System::EventArgs^ e) { this->Size=Drawing::Size(200,300); } Works!
  • 70. References msdn Awesome library C++ , C# , VB.NET , ASP.NET , XNA , XML ... etc http://msdn.microsoft.com/en-us/library/default.aspx
  • 71. That’s it for today!