SlideShare ist ein Scribd-Unternehmen logo
1 von 46
Downloaden Sie, um offline zu lesen
C++.NET
Windows Forms Course
L10-Instantiate Controls At
Runtime

Mohammad Shaker
mohammadshakergtr.wordpress.com
C++.NET Windows Forms Course
@ZGTRShaker
Instantiate Controls at
Runtime
The Concept of
Instantiating Controls at
Runtime
Instantiating at Runtime
• Let’s have the following form
Instantiating at Runtime
• Now, let’s have the following code, what does it mean?
It’s just allocating a memory space for a new object (button)
private: System::Void Form1_Load(System::Object^
System::EventArgs^ e)
{
Button ^MyButton = gcnew Button;
}

• Does it show a button?!!!

sender,
Instantiating at Runtime
NO!
Instantiating at Runtime
• What happens?

private: System::Void Form1_Load(System::Object^
System::EventArgs^ e)
{
Button ^MyButton = gcnew Button;
MyButton->Show();
}

sender,
Instantiating at Runtime
Instantiating at Runtime
• Parent! What happens now?

private: System::Void Form1_Load(System::Object^
System::EventArgs^ e)
{
Button ^MyButton = gcnew Button;
MyButton->Parent = this;
}

sender,
Instantiating at Runtime
• Why?
Instantiating at Runtime
• What happens?
private: System::Void Form1_Load(System::Object^ sender,
System::EventArgs^ e)
{
Button ^MyButton = gcnew Button;
MyButton->Parent = this;
MyButton->Location = System::Drawing::Point(10, 20);
MyButton->Name = L"button1";
MyButton->Size = System::Drawing::Size(75, 23);
MyButton->TabIndex = 0;
MyButton->Text = L"MyDynamicButton";
MyButton->UseVisualStyleBackColor = true;
}
Instantiating at Runtime
How can we fire events on the
newly created button?
The event wire-up in design time
• Consider that we have the following design …
The event wire-up in design time
• And we add a button lick event to button1
_
c
private: System::Void button1_Click(System::Object^
System::EventArgs^ e)
{
MessageBox::Show("HiiiIiIIiIIIIIiiii");
}

sender,
The event wire-up in design time
• Now, we can see the following …
The event wire-up in design time
Instantiating at Runtime
private: System::Void button1_Click(System::Object^
• Now, let’s add sth
System::EventArgs^ e) else!
{
MessageBox::Show("HiiiIiIIiIIIIIiiii");
}

sender,
Instantiating at Runtime
• Now, back to our Button:
private: System::Void Form1_Load(System::Object^ sender,
System::EventArgs^ e)
{
Button ^MyButton = gcnew Button;
MyButton->Parent = this;
MyButton->Location = System::Drawing::Point(10, 20);
MyButton->Name = L"button1";
MyButton->Size = System::Drawing::Size(75, 23);
MyButton->TabIndex = 0;
MyButton->Text = L"MyDynamicButton";
MyButton->UseVisualStyleBackColor = true;
}
Instantiating at Runtime
• We can do this:
private: System::Void Form1_Load(System::Object^ sender,
System::EventArgs^ e)
{
Button ^MyButton = gcnew Button;
MyButton->Parent = this;
MyButton->Location = System::Drawing::Point(10, 20);
MyButton->Name = L"button1";
MyButton->Size = System::Drawing::Size(75, 23);
MyButton->TabIndex = 0;
MyButton->Text = L"MyDynamicButton";
MyButton->UseVisualStyleBackColor = true;
MyButton->Click += gcnew System::EventHandler(this,
&Form1::button1_Click_1);
}
Instantiating at Runtime
• What happens when clicking the created Button “MyButton”
or Button1?
private: System::Void button1_Click_1(System::Object^
sender, System::EventArgs^ e)
{
MessageBox::Show("Wow!!! ");
}
Instantiating at Runtime
Instantiating at Runtime
• We can do this?
private: System::Void Form1_Load(System::Object^ sender,
System::EventArgs^ e)
{
Button ^MyButton = gcnew Button;
MyButton->Parent = this;
MyButton->Location = System::Drawing::Point(10, 20);
MyButton->Name = L"button1";
MyButton->Size = System::Drawing::Size(75, 23);
MyButton->TabIndex = 0;
MyButton->Text = L"MyDynamicButton";
MyButton->UseVisualStyleBackColor = true;
MyButton->Click += gcnew System::EventHandler(this,
&Form1::Mamy);
}
Instantiating at Runtime
• And change it accordingly like this?

private: System::Void Mamy(System::Object^ sender,
System::EventArgs^ e)
{
MessageBox::Show("Mamy is a great cook! :D");
}
Instantiating at Runtime
Instantiating at Runtime
• Now, Consider we have the following two functions
private: System::Void Mamy(System::Object^
System::EventArgs^ e)
{
this->Text = "Mamy";
}

sender,

private: System::Void Chocolate(System::Object^ sender,
System::EventArgs^ e)
{
MessageBox::Show("There's no chocolate to eat :'( ");
}
Instantiating at Runtime
• We can do this? Try it out!
private: System::Void Form1_Load(System::Object^ sender,
System::EventArgs^ e)
{
Button ^MyButton = gcnew Button;
MyButton->Parent = this;
MyButton->Location = System::Drawing::Point(10, 20);
MyButton->Name = L"button1";
MyButton->Size = System::Drawing::Size(75, 23);
MyButton->TabIndex = 0;
MyButton->Text = L"MyDynamicButton";
MyButton->UseVisualStyleBackColor = true;
MyButton->Click += gcnew System::EventHandler(this,
&Form1::Mamy);
MyButton->Click += gcnew System::EventHandler(this,
&Form1::Chocolate);
}
Now, let’s see some more
advanced stuff
Event handling
private: System::Void Form1_Load(System::Object^ sender,
System::EventArgs^ e)
{
Button ^MyButton = gcnew Button;
MyButton->Parent = this;
MyButton->Location = System::Drawing::Point(10, 20);
MyButton->Name = L"button1";
MyButton->Size = System::Drawing::Size(75, 23);
MyButton->TabIndex = 0;
MyButton->Text = L"MyDynamicButton";
MyButton->UseVisualStyleBackColor = true;
MyButton->Click += gcnew System::EventHandler(this,
&Form1::button1_Click_1);
MyButton->MouseHover += gcnew System::EventHandler(this,
&Form1::MyProdHover);
}
Event handling
• Compiler error, why?
private: void MyProdHover (System::Object^
System::EventArgs^ e)
{
while (sender->Width < 200)
{
sender->Width+=3;
sender->Height+=1;
Threading::Thread::Sleep(100);
}
}

sender,
dynamic_cast
• We use dynamic_cast
private: void MyProdHover (System::Object^ sender,
System::EventArgs^ e)
{
while ((dynamic_cast<Button^>(sender))->Width < 200)
{
(dynamic_cast<Button^>(sender))->Refresh();
(dynamic_cast<Button^>(sender))->Width+=3;
(dynamic_cast<Button^>(sender))->Height+=1;
Threading::Thread::Sleep(100);
}
}
dynamic_cast
• We can do this for sure
private: void MyProdHover (System::Object^ sender,
System::EventArgs^ e)
{
Button ^TempButton = (dynamic_cast<Button^>(sender));
while (TempButton->Width < 200)
{
TempButton->Width+=3;
TempButton->Height+=1;
Threading::Thread::Sleep(100);
}
}

• Now what happens? And what should happen?
Event handling
• Test it yourself. After seconds “without” motion the button
becomes like this:

How can we solve this and see the motion?
Event handling
• Refresh method!
private: void MyProdHover (System::Object^ sender,
System::EventArgs^ e)
{
Button ^TempButton = (dynamic_cast<Button^>(sender));
while (TempButton->Width < 200)
{
TempButton->Refresh();
TempButton->Width+=3;
TempButton->Height+=1;
Threading::Thread::Sleep(100);
}
}
Event handling
Event handling
private: System::Void Form1_Load(System::Object^
• Now, let’s adde) following …
the
System::EventArgs^

sender,

{
Button ^MyButton = gcnew Button;
MyButton->Parent = this;
MyButton->Location = System::Drawing::Point(10, 20);
MyButton->Name = L"button1";
MyButton->Size = System::Drawing::Size(75, 23);
MyButton->TabIndex = 0;
MyButton->Text = L"MyDynamicButton";
MyButton->UseVisualStyleBackColor = true;
MyButton->Click += gcnew System::EventHandler(this,
&Form1::button1_Click_1);
MyButton->MouseHover += gcnew System::EventHandler(this,
&Form1::MyProdHover);
MyButton->MouseLeave += gcnew System::EventHandler(this,
&Form1::MyProdLeave);
}
Event handling
• What will happen now?
private: void MyProdLeave (System::Object^ sender,
System::EventArgs^ e)
{
while ((dynamic_cast<Button^>(sender))->Width > 50)
{
(dynamic_cast<Button^>(sender))->Refresh();
(dynamic_cast<Button^>(sender))->Width-=3;
(dynamic_cast<Button^>(sender))->Height+=1;
Threading::Thread::Sleep(100);
}
}
Event handling

Mouse still here
Event handling

Now leaving the button area
Event handling

?
What you can do now
• Now, you can create
– Any control you want
• textBox, pictureBox, panel, label, …. etc

– How you want it
– Controls its behavior
– With the number you want (Save references in lists, array, dictionary!!,
…etc)
Test it live!
That’s it for today!

Weitere ähnliche Inhalte

Was ist angesagt?

C++ Windows Forms L08 - GDI P1
C++ Windows Forms L08 - GDI P1 C++ Windows Forms L08 - GDI P1
C++ Windows Forms L08 - GDI P1 Mohammad Shaker
 
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 88Mahmoud Samir Fayed
 
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 181Mahmoud Samir Fayed
 
SOLID principles with Typescript examples
SOLID principles with Typescript examplesSOLID principles with Typescript examples
SOLID principles with Typescript examplesAndrew Nester
 
SISTEMA DE FACTURACION (Ejemplo desarrollado)
SISTEMA DE FACTURACION (Ejemplo desarrollado)SISTEMA DE FACTURACION (Ejemplo desarrollado)
SISTEMA DE FACTURACION (Ejemplo desarrollado)Darwin Durand
 
Sistema de ventas
Sistema de ventasSistema de ventas
Sistema de ventasDAYANA RETO
 
Visual Studio.Net - Sql Server
Visual Studio.Net - Sql ServerVisual Studio.Net - Sql Server
Visual Studio.Net - Sql ServerDarwin Durand
 
Java programs
Java programsJava programs
Java programsjojeph
 
Do you Promise?
Do you Promise?Do you Promise?
Do you Promise?jungkees
 
Poor Man's Functional Programming
Poor Man's Functional ProgrammingPoor Man's Functional Programming
Poor Man's Functional ProgrammingDmitry Buzdin
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
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 180Mahmoud Samir Fayed
 
A Matter Of Form: Access Forms to make reporting a snap (or a click)
A Matter Of Form: Access Forms to make reporting a snap (or a click)A Matter Of Form: Access Forms to make reporting a snap (or a click)
A Matter Of Form: Access Forms to make reporting a snap (or a click)Alan Manifold
 

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
 
final project for C#
final project for C#final project for C#
final project for C#
 
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
 
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
 
Ete programs
Ete programsEte programs
Ete programs
 
syed
syedsyed
syed
 
SOLID principles with Typescript examples
SOLID principles with Typescript examplesSOLID principles with Typescript examples
SOLID principles with Typescript examples
 
SISTEMA DE FACTURACION (Ejemplo desarrollado)
SISTEMA DE FACTURACION (Ejemplo desarrollado)SISTEMA DE FACTURACION (Ejemplo desarrollado)
SISTEMA DE FACTURACION (Ejemplo desarrollado)
 
Sistema de ventas
Sistema de ventasSistema de ventas
Sistema de ventas
 
Visual Studio.Net - Sql Server
Visual Studio.Net - Sql ServerVisual Studio.Net - Sql Server
Visual Studio.Net - Sql Server
 
Java programs
Java programsJava programs
Java programs
 
Docimp
DocimpDocimp
Docimp
 
Do you Promise?
Do you Promise?Do you Promise?
Do you Promise?
 
BingoConsoleApp
BingoConsoleAppBingoConsoleApp
BingoConsoleApp
 
Poor Man's Functional Programming
Poor Man's Functional ProgrammingPoor Man's Functional Programming
Poor Man's Functional Programming
 
Java script
Java scriptJava script
Java script
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
123
123123
123
 
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
 
A Matter Of Form: Access Forms to make reporting a snap (or a click)
A Matter Of Form: Access Forms to make reporting a snap (or a click)A Matter Of Form: Access Forms to make reporting a snap (or a click)
A Matter Of Form: Access Forms to make reporting a snap (or a click)
 

Andere mochten auch

C# Starter L02-Classes and Objects
C# Starter L02-Classes and ObjectsC# Starter L02-Classes and Objects
C# Starter L02-Classes and ObjectsMohammad Shaker
 
Mobile Software Engineering Crash Course - C01 Intro
Mobile Software Engineering Crash Course - C01 IntroMobile Software Engineering Crash Course - C01 Intro
Mobile Software Engineering Crash Course - C01 IntroMohammad Shaker
 
C# Starter L03-Utilities
C# Starter L03-UtilitiesC# Starter L03-Utilities
C# Starter L03-UtilitiesMohammad Shaker
 
Interaction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile ConstraintsInteraction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile ConstraintsMohammad Shaker
 
C++ Windows Forms L01 - Intro
C++ Windows Forms L01 - IntroC++ Windows Forms L01 - Intro
C++ Windows Forms L01 - IntroMohammad Shaker
 
C# Starter L01-Intro and Warm-up
C# Starter L01-Intro and Warm-upC# Starter L01-Intro and Warm-up
C# Starter L01-Intro and Warm-upMohammad Shaker
 
Unity L01 - Game Development
Unity L01 - Game DevelopmentUnity L01 - Game Development
Unity L01 - Game DevelopmentMohammad Shaker
 

Andere mochten auch (12)

C++ L01-Variables
C++ L01-VariablesC++ L01-Variables
C++ L01-Variables
 
C# Starter L02-Classes and Objects
C# Starter L02-Classes and ObjectsC# Starter L02-Classes and Objects
C# Starter L02-Classes and Objects
 
XNA L01–Introduction
XNA L01–IntroductionXNA L01–Introduction
XNA L01–Introduction
 
Mobile Software Engineering Crash Course - C01 Intro
Mobile Software Engineering Crash Course - C01 IntroMobile Software Engineering Crash Course - C01 Intro
Mobile Software Engineering Crash Course - C01 Intro
 
Delphi L01 Intro
Delphi L01 IntroDelphi L01 Intro
Delphi L01 Intro
 
C# Starter L03-Utilities
C# Starter L03-UtilitiesC# Starter L03-Utilities
C# Starter L03-Utilities
 
Interaction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile ConstraintsInteraction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile Constraints
 
OpenGL Starter L01
OpenGL Starter L01OpenGL Starter L01
OpenGL Starter L01
 
Android L01 - Warm Up
Android L01 - Warm UpAndroid L01 - Warm Up
Android L01 - Warm Up
 
C++ Windows Forms L01 - Intro
C++ Windows Forms L01 - IntroC++ Windows Forms L01 - Intro
C++ Windows Forms L01 - Intro
 
C# Starter L01-Intro and Warm-up
C# Starter L01-Intro and Warm-upC# Starter L01-Intro and Warm-up
C# Starter L01-Intro and Warm-up
 
Unity L01 - Game Development
Unity L01 - Game DevelopmentUnity L01 - Game Development
Unity L01 - Game Development
 

Ähnlich wie C++ Windows Forms L10 - Instantiate

Introj Query Pt2
Introj Query Pt2Introj Query Pt2
Introj Query Pt2kshyju
 
Python is a high-level, general-purpose programming language. Its design phil...
Python is a high-level, general-purpose programming language. Its design phil...Python is a high-level, general-purpose programming language. Its design phil...
Python is a high-level, general-purpose programming language. Its design phil...bhargavi804095
 
intro_gui
intro_guiintro_gui
intro_guifilipb2
 
Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5Bhushan Mulmule
 
Lab StepsSTEP 1 Login Form1. In order to do this lab, we need.docx
Lab StepsSTEP 1 Login Form1. In order to do this lab, we need.docxLab StepsSTEP 1 Login Form1. In order to do this lab, we need.docx
Lab StepsSTEP 1 Login Form1. In order to do this lab, we need.docxsmile790243
 
package buttongui; import static com.sun.deploy.config.JREInf.pdf
package buttongui; import static com.sun.deploy.config.JREInf.pdfpackage buttongui; import static com.sun.deploy.config.JREInf.pdf
package buttongui; import static com.sun.deploy.config.JREInf.pdfarjuntiwari586
 
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAMPROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAMSaraswathiRamalingam
 
10 awt event model
10 awt event model10 awt event model
10 awt event modelBayarkhuu
 
Construct 2 Platformer: Step by Step
Construct 2 Platformer: Step by StepConstruct 2 Platformer: Step by Step
Construct 2 Platformer: Step by StepShahed Chowdhuri
 
Windows Forms For Beginners Part - 4
Windows Forms For Beginners Part - 4Windows Forms For Beginners Part - 4
Windows Forms For Beginners Part - 4Bhushan Mulmule
 
DOT NET LAB PROGRAM PERIYAR UNIVERSITY
DOT NET LAB PROGRAM PERIYAR UNIVERSITY DOT NET LAB PROGRAM PERIYAR UNIVERSITY
DOT NET LAB PROGRAM PERIYAR UNIVERSITY GOKUL SREE
 
UI Design From Scratch - Part 5 - transcript.pdf
UI Design From Scratch - Part 5 - transcript.pdfUI Design From Scratch - Part 5 - transcript.pdf
UI Design From Scratch - Part 5 - transcript.pdfShaiAlmog1
 
DOT NET LAB PROGRAM PERIYAR UNIVERSITY
DOT NET LAB PROGRAM PERIYAR UNIVERSITY DOT NET LAB PROGRAM PERIYAR UNIVERSITY
DOT NET LAB PROGRAM PERIYAR UNIVERSITY GOKUL SREE
 
The three layers of testing
The three layers of testingThe three layers of testing
The three layers of testingBart Waardenburg
 
ExplanationDesignerCodeGlobal.Microsoft.VisualBasic.Compiler.docx
ExplanationDesignerCodeGlobal.Microsoft.VisualBasic.Compiler.docxExplanationDesignerCodeGlobal.Microsoft.VisualBasic.Compiler.docx
ExplanationDesignerCodeGlobal.Microsoft.VisualBasic.Compiler.docxSusanaFurman449
 

Ähnlich wie C++ Windows Forms L10 - Instantiate (20)

Introj Query Pt2
Introj Query Pt2Introj Query Pt2
Introj Query Pt2
 
Teclado word
Teclado wordTeclado word
Teclado word
 
Python is a high-level, general-purpose programming language. Its design phil...
Python is a high-level, general-purpose programming language. Its design phil...Python is a high-level, general-purpose programming language. Its design phil...
Python is a high-level, general-purpose programming language. Its design phil...
 
intro_gui
intro_guiintro_gui
intro_gui
 
Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5
 
Lab StepsSTEP 1 Login Form1. In order to do this lab, we need.docx
Lab StepsSTEP 1 Login Form1. In order to do this lab, we need.docxLab StepsSTEP 1 Login Form1. In order to do this lab, we need.docx
Lab StepsSTEP 1 Login Form1. In order to do this lab, we need.docx
 
package buttongui; import static com.sun.deploy.config.JREInf.pdf
package buttongui; import static com.sun.deploy.config.JREInf.pdfpackage buttongui; import static com.sun.deploy.config.JREInf.pdf
package buttongui; import static com.sun.deploy.config.JREInf.pdf
 
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAMPROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
 
Ditec esoft C# project
Ditec esoft C# project Ditec esoft C# project
Ditec esoft C# project
 
Ditec esoft C# project
Ditec esoft C# projectDitec esoft C# project
Ditec esoft C# project
 
Metode
MetodeMetode
Metode
 
10 awt event model
10 awt event model10 awt event model
10 awt event model
 
Construct 2 Platformer: Step by Step
Construct 2 Platformer: Step by StepConstruct 2 Platformer: Step by Step
Construct 2 Platformer: Step by Step
 
Windows Forms For Beginners Part - 4
Windows Forms For Beginners Part - 4Windows Forms For Beginners Part - 4
Windows Forms For Beginners Part - 4
 
DOT NET LAB PROGRAM PERIYAR UNIVERSITY
DOT NET LAB PROGRAM PERIYAR UNIVERSITY DOT NET LAB PROGRAM PERIYAR UNIVERSITY
DOT NET LAB PROGRAM PERIYAR UNIVERSITY
 
UI Design From Scratch - Part 5 - transcript.pdf
UI Design From Scratch - Part 5 - transcript.pdfUI Design From Scratch - Part 5 - transcript.pdf
UI Design From Scratch - Part 5 - transcript.pdf
 
DOT NET LAB PROGRAM PERIYAR UNIVERSITY
DOT NET LAB PROGRAM PERIYAR UNIVERSITY DOT NET LAB PROGRAM PERIYAR UNIVERSITY
DOT NET LAB PROGRAM PERIYAR UNIVERSITY
 
The three layers of testing
The three layers of testingThe three layers of testing
The three layers of testing
 
37c
37c37c
37c
 
ExplanationDesignerCodeGlobal.Microsoft.VisualBasic.Compiler.docx
ExplanationDesignerCodeGlobal.Microsoft.VisualBasic.Compiler.docxExplanationDesignerCodeGlobal.Microsoft.VisualBasic.Compiler.docx
ExplanationDesignerCodeGlobal.Microsoft.VisualBasic.Compiler.docx
 

Mehr von Mohammad Shaker

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 GraduateMohammad Shaker
 
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]Mohammad Shaker
 
Interaction Design L06 - Tricks with Psychology
Interaction Design L06 - Tricks with PsychologyInteraction Design L06 - Tricks with Psychology
Interaction Design L06 - Tricks with PsychologyMohammad Shaker
 
Short, Matters, Love - Passioneers Event 2015
Short, Matters, Love -  Passioneers Event 2015Short, Matters, Love -  Passioneers Event 2015
Short, Matters, Love - Passioneers Event 2015Mohammad Shaker
 
Android L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and WearablesAndroid L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and WearablesMohammad Shaker
 
Interaction Design L03 - Color
Interaction Design L03 - ColorInteraction Design L03 - Color
Interaction Design L03 - ColorMohammad Shaker
 
Interaction Design L05 - Typography
Interaction Design L05 - TypographyInteraction Design L05 - Typography
Interaction Design L05 - TypographyMohammad Shaker
 
Interaction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and CouplingInteraction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and CouplingMohammad Shaker
 
Android L04 - Notifications and Threading
Android L04 - Notifications and ThreadingAndroid L04 - Notifications and Threading
Android L04 - Notifications and ThreadingMohammad Shaker
 
Android L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOSAndroid L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOSMohammad Shaker
 
Interaction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and GridsInteraction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and GridsMohammad Shaker
 
Android L10 - Stores and Gaming
Android L10 - Stores and GamingAndroid L10 - Stores and Gaming
Android L10 - Stores and GamingMohammad Shaker
 
Android L06 - Cloud / Parse
Android L06 - Cloud / ParseAndroid L06 - Cloud / Parse
Android L06 - Cloud / ParseMohammad Shaker
 
Android L08 - Google Maps and Utilities
Android L08 - Google Maps and UtilitiesAndroid L08 - Google Maps and Utilities
Android L08 - Google Maps and UtilitiesMohammad Shaker
 
Android L03 - Styles and Themes
Android L03 - Styles and Themes Android L03 - Styles and Themes
Android L03 - Styles and Themes Mohammad Shaker
 
Android L02 - Activities and Adapters
Android L02 - Activities and AdaptersAndroid L02 - Activities and Adapters
Android L02 - Activities and AdaptersMohammad Shaker
 
Indie Series 03: Becoming an Indie
Indie Series 03: Becoming an IndieIndie Series 03: Becoming an Indie
Indie Series 03: Becoming an IndieMohammad Shaker
 
Indie Series 01: Intro to Games
Indie Series 01: Intro to GamesIndie Series 01: Intro to Games
Indie Series 01: Intro to GamesMohammad Shaker
 
Indie Series 04: The Making of SyncSeven
Indie Series 04: The Making of SyncSevenIndie Series 04: The Making of SyncSeven
Indie Series 04: The Making of SyncSevenMohammad 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
 
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 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
 
Indie Series 03: Becoming an Indie
Indie Series 03: Becoming an IndieIndie Series 03: Becoming an Indie
Indie Series 03: Becoming an Indie
 
Indie Series 01: Intro to Games
Indie Series 01: Intro to GamesIndie Series 01: Intro to Games
Indie Series 01: Intro to Games
 
Indie Series 04: The Making of SyncSeven
Indie Series 04: The Making of SyncSevenIndie Series 04: The Making of SyncSeven
Indie Series 04: The Making of SyncSeven
 

Kürzlich hochgeladen

Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 

Kürzlich hochgeladen (20)

Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 

C++ Windows Forms L10 - Instantiate

  • 1. C++.NET Windows Forms Course L10-Instantiate Controls At Runtime Mohammad Shaker mohammadshakergtr.wordpress.com C++.NET Windows Forms Course @ZGTRShaker
  • 2.
  • 3.
  • 4.
  • 6. The Concept of Instantiating Controls at Runtime
  • 7. Instantiating at Runtime • Let’s have the following form
  • 8. Instantiating at Runtime • Now, let’s have the following code, what does it mean? It’s just allocating a memory space for a new object (button) private: System::Void Form1_Load(System::Object^ System::EventArgs^ e) { Button ^MyButton = gcnew Button; } • Does it show a button?!!! sender,
  • 10. Instantiating at Runtime • What happens? private: System::Void Form1_Load(System::Object^ System::EventArgs^ e) { Button ^MyButton = gcnew Button; MyButton->Show(); } sender,
  • 12. Instantiating at Runtime • Parent! What happens now? private: System::Void Form1_Load(System::Object^ System::EventArgs^ e) { Button ^MyButton = gcnew Button; MyButton->Parent = this; } sender,
  • 14. Instantiating at Runtime • What happens? private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { Button ^MyButton = gcnew Button; MyButton->Parent = this; MyButton->Location = System::Drawing::Point(10, 20); MyButton->Name = L"button1"; MyButton->Size = System::Drawing::Size(75, 23); MyButton->TabIndex = 0; MyButton->Text = L"MyDynamicButton"; MyButton->UseVisualStyleBackColor = true; }
  • 16. How can we fire events on the newly created button?
  • 17. The event wire-up in design time • Consider that we have the following design …
  • 18. The event wire-up in design time • And we add a button lick event to button1 _ c private: System::Void button1_Click(System::Object^ System::EventArgs^ e) { MessageBox::Show("HiiiIiIIiIIIIIiiii"); } sender,
  • 19. The event wire-up in design time • Now, we can see the following …
  • 20. The event wire-up in design time
  • 21. Instantiating at Runtime private: System::Void button1_Click(System::Object^ • Now, let’s add sth System::EventArgs^ e) else! { MessageBox::Show("HiiiIiIIiIIIIIiiii"); } sender,
  • 22. Instantiating at Runtime • Now, back to our Button: private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { Button ^MyButton = gcnew Button; MyButton->Parent = this; MyButton->Location = System::Drawing::Point(10, 20); MyButton->Name = L"button1"; MyButton->Size = System::Drawing::Size(75, 23); MyButton->TabIndex = 0; MyButton->Text = L"MyDynamicButton"; MyButton->UseVisualStyleBackColor = true; }
  • 23. Instantiating at Runtime • We can do this: private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { Button ^MyButton = gcnew Button; MyButton->Parent = this; MyButton->Location = System::Drawing::Point(10, 20); MyButton->Name = L"button1"; MyButton->Size = System::Drawing::Size(75, 23); MyButton->TabIndex = 0; MyButton->Text = L"MyDynamicButton"; MyButton->UseVisualStyleBackColor = true; MyButton->Click += gcnew System::EventHandler(this, &Form1::button1_Click_1); }
  • 24. Instantiating at Runtime • What happens when clicking the created Button “MyButton” or Button1? private: System::Void button1_Click_1(System::Object^ sender, System::EventArgs^ e) { MessageBox::Show("Wow!!! "); }
  • 26. Instantiating at Runtime • We can do this? private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { Button ^MyButton = gcnew Button; MyButton->Parent = this; MyButton->Location = System::Drawing::Point(10, 20); MyButton->Name = L"button1"; MyButton->Size = System::Drawing::Size(75, 23); MyButton->TabIndex = 0; MyButton->Text = L"MyDynamicButton"; MyButton->UseVisualStyleBackColor = true; MyButton->Click += gcnew System::EventHandler(this, &Form1::Mamy); }
  • 27. Instantiating at Runtime • And change it accordingly like this? private: System::Void Mamy(System::Object^ sender, System::EventArgs^ e) { MessageBox::Show("Mamy is a great cook! :D"); }
  • 29. Instantiating at Runtime • Now, Consider we have the following two functions private: System::Void Mamy(System::Object^ System::EventArgs^ e) { this->Text = "Mamy"; } sender, private: System::Void Chocolate(System::Object^ sender, System::EventArgs^ e) { MessageBox::Show("There's no chocolate to eat :'( "); }
  • 30. Instantiating at Runtime • We can do this? Try it out! private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { Button ^MyButton = gcnew Button; MyButton->Parent = this; MyButton->Location = System::Drawing::Point(10, 20); MyButton->Name = L"button1"; MyButton->Size = System::Drawing::Size(75, 23); MyButton->TabIndex = 0; MyButton->Text = L"MyDynamicButton"; MyButton->UseVisualStyleBackColor = true; MyButton->Click += gcnew System::EventHandler(this, &Form1::Mamy); MyButton->Click += gcnew System::EventHandler(this, &Form1::Chocolate); }
  • 31. Now, let’s see some more advanced stuff
  • 32. Event handling private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { Button ^MyButton = gcnew Button; MyButton->Parent = this; MyButton->Location = System::Drawing::Point(10, 20); MyButton->Name = L"button1"; MyButton->Size = System::Drawing::Size(75, 23); MyButton->TabIndex = 0; MyButton->Text = L"MyDynamicButton"; MyButton->UseVisualStyleBackColor = true; MyButton->Click += gcnew System::EventHandler(this, &Form1::button1_Click_1); MyButton->MouseHover += gcnew System::EventHandler(this, &Form1::MyProdHover); }
  • 33. Event handling • Compiler error, why? private: void MyProdHover (System::Object^ System::EventArgs^ e) { while (sender->Width < 200) { sender->Width+=3; sender->Height+=1; Threading::Thread::Sleep(100); } } sender,
  • 34. dynamic_cast • We use dynamic_cast private: void MyProdHover (System::Object^ sender, System::EventArgs^ e) { while ((dynamic_cast<Button^>(sender))->Width < 200) { (dynamic_cast<Button^>(sender))->Refresh(); (dynamic_cast<Button^>(sender))->Width+=3; (dynamic_cast<Button^>(sender))->Height+=1; Threading::Thread::Sleep(100); } }
  • 35. dynamic_cast • We can do this for sure private: void MyProdHover (System::Object^ sender, System::EventArgs^ e) { Button ^TempButton = (dynamic_cast<Button^>(sender)); while (TempButton->Width < 200) { TempButton->Width+=3; TempButton->Height+=1; Threading::Thread::Sleep(100); } } • Now what happens? And what should happen?
  • 36. Event handling • Test it yourself. After seconds “without” motion the button becomes like this: How can we solve this and see the motion?
  • 37. Event handling • Refresh method! private: void MyProdHover (System::Object^ sender, System::EventArgs^ e) { Button ^TempButton = (dynamic_cast<Button^>(sender)); while (TempButton->Width < 200) { TempButton->Refresh(); TempButton->Width+=3; TempButton->Height+=1; Threading::Thread::Sleep(100); } }
  • 39. Event handling private: System::Void Form1_Load(System::Object^ • Now, let’s adde) following … the System::EventArgs^ sender, { Button ^MyButton = gcnew Button; MyButton->Parent = this; MyButton->Location = System::Drawing::Point(10, 20); MyButton->Name = L"button1"; MyButton->Size = System::Drawing::Size(75, 23); MyButton->TabIndex = 0; MyButton->Text = L"MyDynamicButton"; MyButton->UseVisualStyleBackColor = true; MyButton->Click += gcnew System::EventHandler(this, &Form1::button1_Click_1); MyButton->MouseHover += gcnew System::EventHandler(this, &Form1::MyProdHover); MyButton->MouseLeave += gcnew System::EventHandler(this, &Form1::MyProdLeave); }
  • 40. Event handling • What will happen now? private: void MyProdLeave (System::Object^ sender, System::EventArgs^ e) { while ((dynamic_cast<Button^>(sender))->Width > 50) { (dynamic_cast<Button^>(sender))->Refresh(); (dynamic_cast<Button^>(sender))->Width-=3; (dynamic_cast<Button^>(sender))->Height+=1; Threading::Thread::Sleep(100); } }
  • 42. Event handling Now leaving the button area
  • 44. What you can do now • Now, you can create – Any control you want • textBox, pictureBox, panel, label, …. etc – How you want it – Controls its behavior – With the number you want (Save references in lists, array, dictionary!!, …etc)
  • 46. That’s it for today!