SlideShare una empresa de Scribd logo
1 de 39
Descargar para leer sin conexión
C++.NET
Windows Forms Course
L11-Inheritance

Mohammad Shaker
mohammadshakergtr.wordpress.com
C++.NET Windows Forms Course
@ZGTRShaker
Inheritance
the concept
Inheritance
• Now, let’s have the following class:
#pragma once
using namespace::System;
ref class MyClass
{
public:
MyClass(void);
virtual String ^ToString() override;
};
Inheritance

#include "StdAfx.h"
#include "MyClass.h"
MyClass::MyClass(void)
{}

String^ MyClass::ToString()
{
return "I won't red 3leek :P:P ";
};
Inheritance
• What happens?
private: System::Void button1_Click(System::Object^
System::EventArgs^ e)
{
MyClass ^MC = gcnew MyClass;
textBox1->Text = MC->ToString();
}

sender,
Inheritance
• Let’s get it bigger a little
#pragma once
using namespace::System;
ref class MyClass
{
public:
MyClass(String^ s1, String^ s2);
virtual String ^ToString() override;
private:
String ^FName;
String ^LName;
};
Inheritance
#include "StdAfx.h"
#include "MyClass.h"
MyClass::MyClass(String^ s1, String^ s2)
{
FName = s1; LName = s2;
}

String^ MyClass::ToString()
{
return String::Format("{0}{1}{2}{3}", "My name is : ",
FName, " ", LName);
};
Inheritance
• What happens?
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
MyClass ^MC = gcnew MyClass("MeMe", "Auf-Wiedersehen");
textBox1->Text = MC->ToString();
}
Inheritance
• Let’s have the following ref class.
• Everything ok?
#pragma once

ref class MyClass : System::Windows::Forms::Button
{
public:
MyClass(void);
};
Compiler error, why?
Inheritance
#pragma once
using namespace System;

ref class MyClass : System::Windows::Forms::Button
{

public:
MyClass(void);
};
Inheritance
• Why doing this?
#pragma once
using namespace System;
namespace dotNet8_Inher {
ref class Form1;

Forward declaration

ref class MyClass : System::Windows::Forms::Button
{
public: MyClass(void);
};
}
Inheritance
• .cpp file
#include "StdAfx.h"
#include "MyClass.h"
namespace dotNet8_Inher {
MyClass::MyClass(void)
{}
}
Inheritance
• In Form1.h
private: System::Void Form1_Load(System::Object^
sender, System::EventArgs^ e)
{
MyClass ^MC = gcnew MyClass;
}

• Sth needed?  for Controls?
• In Form1.h
private: System::Void Form1_Load(System::Object^
sender, System::EventArgs^ e)
{
MyClass ^MC = gcnew MyClass;
MC->Parent = this;
}

• What will happen now?
Inheritance
Inheritance
• Now, let’s have the following in cpp file
#include "StdAfx.h"
#include "MyClass.h"

namespace dotNet8_Inher {
MyClass::MyClass(void)
{
this->Text = "I'M HAPPY!";
}
}
Inheritance
• Again, in Form1.h
private: System::Void Form1_Load(System::Object^
sender, System::EventArgs^ e)
{
MyClass ^MC = gcnew MyClass;
MC ->Parent = this;
}

• What will happen now?
Inheritance
#include "StdAfx.h"
#include "MyClass.h"

namespace dotNet8_Inher {
MyClass::MyClass(void)
{
this->Location = System::Drawing::Point(223, 121);
this->Name = L"button1";
this->Size = System::Drawing::Size(75, 23);
this->TabIndex = 0;
this->Text = L"My Button!";
this->UseVisualStyleBackColor = true;
}
}
private: System::Void Form1_Load(System::Object^
System::EventArgs^ e)
{
MyClass ^MC = gcnew MyClass;
MC ->Parent = this;
}

sender,
Inheritance
A way to steal :D
Multiple Inheritance
The concept
Multiple Inheritance
• Now, let’s see the following crazy code
#pragma once
using namespace System;
namespace dotNet8_Inheir {
ref class Form1;
ref class MyClass : System::Windows::Forms::Button,
System::Windows::Forms::ComboBox
{
private:
Form1 ^MyForm;
public:
MyClass(Form1 ^f);
};
}
#include "StdAfx.h"
#include "MyClass.h"

namespace dotNet8_Inheir {

MyClass::MyClass(void)
{
this->Location = System::Drawing::Point(223, 121);
this->Name = L"button1";
this->Size = System::Drawing::Size(75, 23);
this->TabIndex = 0;
this->Text = L"My Button!";
this->UseVisualStyleBackColor = true;
}
}
private: System::Void Form1_Load(System::Object^
System::EventArgs^ e)
{
MyClass ^MC = gcnew MyClass;
MC ->Parent = this;
}

sender,
Compiler error
Ambiguous, Why?
Multiple Inheritance
• Why?
– Can’t know the “location” peoperties is for!
– Can’t inhert from more than one base class in.NET!

• So, what to do?
– Dump fix. (Do Not Do it (DNDI) unlsess necessary)
Multiple Inheritance - DNDI
#pragma once
using namespace System;
namespace dotNet8_Inheir {
ref class Form1;
ref class MyClass : public System::Windows::Forms::Button
{
private:
Form1 ^MyForm;
System::Windows::Forms::ComboBox ^MyCB;
public:
MyClass(Form1 ^f);
void InitializeButton();
void
InitializeComboBox(System::Windows::Forms::ComboBox ^%);
};
}
#include "StdAfx.h"
#include "MyClass.h”
namespace dotNet8_Inheir
{
MyClass::MyClass(Form1 ^f)
{
MyForm = f;
InitializeButton();
InitializeComboBox(MyCB);
}
void MyClass::InitializeButton()
{
this->Location = System::Drawing::Point(223, 121);
this->Name = L"button1";
this->Size = System::Drawing::Size(75, 23);
this->TabIndex = 0;
this->Text = L"My Button!";
this->UseVisualStyleBackColor = true;
}
void MyClass::InitializeComboBox(System::Windows::Forms::ComboBox ^%CB)
{
CB = gcnew System::Windows::Forms::ComboBox;
CB->Location = System::Drawing::Point(223, 121);
CB->Size = System::Drawing::Size(75, 23);
CB->TabIndex = 0;
CB->Text = L"My ComboBox!";
CB->Parent = this;
}
}
Multiple Inheritance - DNDI
• Let’s start all over again
private: System::Void Form1_Load(System::Object^
System::EventArgs^ e)
{
MyClass ^MC;
MC = gcnew MyClass(this);
}

sender,
Multiple Inheritance - DNDI
#pragma once
using namespace System;
namespace dotNet8_Inheir {
ref class Form1;
ref class MyClass : public System::Windows::Forms::Button
{
private:
Form1 ^MyForm;
System::Windows::Forms::ComboBox ^MyCB;
public:
MyClass(Form1 ^f);
void InitializeButton();
void InitializeComboBox(System::Windows::Forms::ComboBox ^%);
void PlayIt(System::Object^ sender, System::EventArgs^ e);
void comboBox1_SelectedIndexChanged(System::Object^ sender,
System::EventArgs^ e);
};
}
#include "StdAfx.h"
#include "MyClass.h"
#include "Form1.h"
namespace dotNet8_Inheir
{
MyClass::MyClass(Form1 ^f)
{
MyForm = f;
this->Parent = MyForm;
InitializeButton();
InitializeComboBox(MyCB);
}

void MyClass::InitializeButton()
{
this->Button::Location = System::Drawing::Point(223, 121);
this->Name = L"button1";
this->Size = System::Drawing::Size(75, 23);
this->TabIndex = 0;
this->Text = L"My Button!";
this->UseVisualStyleBackColor = true;
this->Click += gcnew System::EventHandler(this, &MyClass::PlayIt);
}
void MyClass::InitializeComboBox(System::Windows::Forms::ComboBox ^%CB)
{
CB = gcnew System::Windows::Forms::ComboBox;
CB->FormattingEnabled = true;
CB->Location = System::Drawing::Point(100, 100);
CB->Size = System::Drawing::Size(121, 21);
CB->TabIndex = 2;
MyCB->Parent = MyClass::Parent;
CB->SelectedIndexChanged += gcnew System::EventHandler(this,
&MyClass::comboBox1_SelectedIndexChanged);
}
void MyClass::PlayIt(System::Object^ sender, System::EventArgs^ e)
{
Drawing::Point P = (dynamic_cast <Button^> (sender))->Location;
MyCB->Location = P;
}
void MyClass::comboBox1_SelectedIndexChanged(System::Object^
System::EventArgs^ e)

{
}
}

sender,
Multiple Inheritance - DNDI

After pressing the button
Keep in touch:
mohammadshakergtr@gmail.com
http://mohammadshakergtr.wordpress.com/
tweet @ZGTRShaker
Go have some fun!

Más contenido relacionado

La actualidad más candente

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.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 202Mahmoud Samir Fayed
 
Apache Flink Training: DataStream API Part 2 Advanced
Apache Flink Training: DataStream API Part 2 Advanced Apache Flink Training: DataStream API Part 2 Advanced
Apache Flink Training: DataStream API Part 2 Advanced Flink Forward
 
Mocks introduction
Mocks introductionMocks introduction
Mocks introductionSperasoft
 
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
 
Apache Flink Training: DataSet API Basics
Apache Flink Training: DataSet API BasicsApache Flink Training: DataSet API Basics
Apache Flink Training: DataSet API BasicsFlink Forward
 
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.Kuldeep Jain
 
C# Starter L07-Objects Cloning
C# Starter L07-Objects CloningC# Starter L07-Objects Cloning
C# Starter L07-Objects CloningMohammad Shaker
 
Functional Stream Processing with Scalaz-Stream
Functional Stream Processing with Scalaz-StreamFunctional Stream Processing with Scalaz-Stream
Functional Stream Processing with Scalaz-StreamAdil Akhter
 
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
 
Writing Domain-Specific Languages for BeepBeep
Writing Domain-Specific Languages for BeepBeepWriting Domain-Specific Languages for BeepBeep
Writing Domain-Specific Languages for BeepBeepSylvain Hallé
 
Chat Room System using Java Swing
Chat Room System using Java SwingChat Room System using Java Swing
Chat Room System using Java SwingTejas Garodia
 
Java programs
Java programsJava programs
Java programsjojeph
 
FS2 for Fun and Profit
FS2 for Fun and ProfitFS2 for Fun and Profit
FS2 for Fun and ProfitAdil Akhter
 

La actualidad más candente (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
 
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
 
Apache Flink Training: DataStream API Part 2 Advanced
Apache Flink Training: DataStream API Part 2 Advanced Apache Flink Training: DataStream API Part 2 Advanced
Apache Flink Training: DataStream API Part 2 Advanced
 
.net progrmming part4
.net progrmming part4.net progrmming part4
.net progrmming part4
 
Mocks introduction
Mocks introductionMocks introduction
Mocks introduction
 
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
 
Dotnet 18
Dotnet 18Dotnet 18
Dotnet 18
 
Apache Flink Training: DataSet API Basics
Apache Flink Training: DataSet API BasicsApache Flink Training: DataSet API Basics
Apache Flink Training: DataSet API Basics
 
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.
 
final project for C#
final project for C#final project for C#
final project for C#
 
C# Starter L07-Objects Cloning
C# Starter L07-Objects CloningC# Starter L07-Objects Cloning
C# Starter L07-Objects Cloning
 
Functional Stream Processing with Scalaz-Stream
Functional Stream Processing with Scalaz-StreamFunctional Stream Processing with Scalaz-Stream
Functional Stream Processing with Scalaz-Stream
 
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
 
syed
syedsyed
syed
 
Writing Domain-Specific Languages for BeepBeep
Writing Domain-Specific Languages for BeepBeepWriting Domain-Specific Languages for BeepBeep
Writing Domain-Specific Languages for BeepBeep
 
Chat Room System using Java Swing
Chat Room System using Java SwingChat Room System using Java Swing
Chat Room System using Java Swing
 
Java programs
Java programsJava programs
Java programs
 
FS2 for Fun and Profit
FS2 for Fun and ProfitFS2 for Fun and Profit
FS2 for Fun and Profit
 
Comparing JVM languages
Comparing JVM languagesComparing JVM languages
Comparing JVM languages
 

Similar a C++ Windows Forms L11 - Inheritance

A la découverte de TypeScript
A la découverte de TypeScriptA la découverte de TypeScript
A la découverte de TypeScriptDenis Voituron
 
The Ring programming language version 1.5.3 book - Part 12 of 184
The Ring programming language version 1.5.3 book - Part 12 of 184The Ring programming language version 1.5.3 book - Part 12 of 184
The Ring programming language version 1.5.3 book - Part 12 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 54 of 210
The Ring programming language version 1.9 book - Part 54 of 210The Ring programming language version 1.9 book - Part 54 of 210
The Ring programming language version 1.9 book - Part 54 of 210Mahmoud Samir Fayed
 
Extreme Swift
Extreme SwiftExtreme Swift
Extreme SwiftMovel
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manualsameer farooq
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Domenic Denicola
 
Gae icc fall2011
Gae icc fall2011Gae icc fall2011
Gae icc fall2011Juan Gomez
 
The Ring programming language version 1.3 book - Part 5 of 88
The Ring programming language version 1.3 book - Part 5 of 88The Ring programming language version 1.3 book - Part 5 of 88
The Ring programming language version 1.3 book - Part 5 of 88Mahmoud Samir Fayed
 
Ensure code quality with vs2012
Ensure code quality with vs2012Ensure code quality with vs2012
Ensure code quality with vs2012Sandeep Joshi
 

Similar a C++ Windows Forms L11 - Inheritance (20)

37c
37c37c
37c
 
Anti patterns
Anti patternsAnti patterns
Anti patterns
 
A la découverte de TypeScript
A la découverte de TypeScriptA la découverte de TypeScript
A la découverte de TypeScript
 
Java VS Python
Java VS PythonJava VS Python
Java VS Python
 
The Ring programming language version 1.5.3 book - Part 12 of 184
The Ring programming language version 1.5.3 book - Part 12 of 184The Ring programming language version 1.5.3 book - Part 12 of 184
The Ring programming language version 1.5.3 book - Part 12 of 184
 
The Ring programming language version 1.9 book - Part 54 of 210
The Ring programming language version 1.9 book - Part 54 of 210The Ring programming language version 1.9 book - Part 54 of 210
The Ring programming language version 1.9 book - Part 54 of 210
 
delegates
delegatesdelegates
delegates
 
Namespace
NamespaceNamespace
Namespace
 
Extreme Swift
Extreme SwiftExtreme Swift
Extreme Swift
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
 
Diifeerences In C#
Diifeerences In C#Diifeerences In C#
Diifeerences In C#
 
Gae icc fall2011
Gae icc fall2011Gae icc fall2011
Gae icc fall2011
 
XAML/C# to HTML/JS
XAML/C# to HTML/JSXAML/C# to HTML/JS
XAML/C# to HTML/JS
 
Collection
CollectionCollection
Collection
 
Closer look at classes
Closer look at classesCloser look at classes
Closer look at classes
 
The Ring programming language version 1.3 book - Part 5 of 88
The Ring programming language version 1.3 book - Part 5 of 88The Ring programming language version 1.3 book - Part 5 of 88
The Ring programming language version 1.3 book - Part 5 of 88
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
 
Ensure code quality with vs2012
Ensure code quality with vs2012Ensure code quality with vs2012
Ensure code quality with vs2012
 
Csharp generics
Csharp genericsCsharp generics
Csharp generics
 

Más de 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
 
Unity L01 - Game Development
Unity L01 - Game DevelopmentUnity L01 - Game Development
Unity L01 - Game DevelopmentMohammad 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 L01 - Mobile Constraints
Interaction Design L01 - Mobile ConstraintsInteraction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile ConstraintsMohammad 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
 

Más de 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
 

Último

"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
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
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
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
 
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
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
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
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
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
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 

Último (20)

"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
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
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
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...
 
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
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
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
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
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!
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 

C++ Windows Forms L11 - Inheritance

  • 1. C++.NET Windows Forms Course L11-Inheritance Mohammad Shaker mohammadshakergtr.wordpress.com C++.NET Windows Forms Course @ZGTRShaker
  • 2.
  • 3.
  • 4.
  • 6. Inheritance • Now, let’s have the following class: #pragma once using namespace::System; ref class MyClass { public: MyClass(void); virtual String ^ToString() override; };
  • 7. Inheritance #include "StdAfx.h" #include "MyClass.h" MyClass::MyClass(void) {} String^ MyClass::ToString() { return "I won't red 3leek :P:P "; };
  • 8. Inheritance • What happens? private: System::Void button1_Click(System::Object^ System::EventArgs^ e) { MyClass ^MC = gcnew MyClass; textBox1->Text = MC->ToString(); } sender,
  • 9. Inheritance • Let’s get it bigger a little #pragma once using namespace::System; ref class MyClass { public: MyClass(String^ s1, String^ s2); virtual String ^ToString() override; private: String ^FName; String ^LName; };
  • 10. Inheritance #include "StdAfx.h" #include "MyClass.h" MyClass::MyClass(String^ s1, String^ s2) { FName = s1; LName = s2; } String^ MyClass::ToString() { return String::Format("{0}{1}{2}{3}", "My name is : ", FName, " ", LName); };
  • 11. Inheritance • What happens? private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { MyClass ^MC = gcnew MyClass("MeMe", "Auf-Wiedersehen"); textBox1->Text = MC->ToString(); }
  • 12. Inheritance • Let’s have the following ref class. • Everything ok? #pragma once ref class MyClass : System::Windows::Forms::Button { public: MyClass(void); }; Compiler error, why?
  • 13. Inheritance #pragma once using namespace System; ref class MyClass : System::Windows::Forms::Button { public: MyClass(void); };
  • 14. Inheritance • Why doing this? #pragma once using namespace System; namespace dotNet8_Inher { ref class Form1; Forward declaration ref class MyClass : System::Windows::Forms::Button { public: MyClass(void); }; }
  • 15. Inheritance • .cpp file #include "StdAfx.h" #include "MyClass.h" namespace dotNet8_Inher { MyClass::MyClass(void) {} }
  • 16. Inheritance • In Form1.h private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { MyClass ^MC = gcnew MyClass; } • Sth needed? for Controls? • In Form1.h private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { MyClass ^MC = gcnew MyClass; MC->Parent = this; } • What will happen now?
  • 18. Inheritance • Now, let’s have the following in cpp file #include "StdAfx.h" #include "MyClass.h" namespace dotNet8_Inher { MyClass::MyClass(void) { this->Text = "I'M HAPPY!"; } }
  • 19. Inheritance • Again, in Form1.h private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { MyClass ^MC = gcnew MyClass; MC ->Parent = this; } • What will happen now?
  • 21. #include "StdAfx.h" #include "MyClass.h" namespace dotNet8_Inher { MyClass::MyClass(void) { this->Location = System::Drawing::Point(223, 121); this->Name = L"button1"; this->Size = System::Drawing::Size(75, 23); this->TabIndex = 0; this->Text = L"My Button!"; this->UseVisualStyleBackColor = true; } } private: System::Void Form1_Load(System::Object^ System::EventArgs^ e) { MyClass ^MC = gcnew MyClass; MC ->Parent = this; } sender,
  • 23. A way to steal :D
  • 25. Multiple Inheritance • Now, let’s see the following crazy code #pragma once using namespace System; namespace dotNet8_Inheir { ref class Form1; ref class MyClass : System::Windows::Forms::Button, System::Windows::Forms::ComboBox { private: Form1 ^MyForm; public: MyClass(Form1 ^f); }; }
  • 26. #include "StdAfx.h" #include "MyClass.h" namespace dotNet8_Inheir { MyClass::MyClass(void) { this->Location = System::Drawing::Point(223, 121); this->Name = L"button1"; this->Size = System::Drawing::Size(75, 23); this->TabIndex = 0; this->Text = L"My Button!"; this->UseVisualStyleBackColor = true; } } private: System::Void Form1_Load(System::Object^ System::EventArgs^ e) { MyClass ^MC = gcnew MyClass; MC ->Parent = this; } sender,
  • 28.
  • 29. Multiple Inheritance • Why? – Can’t know the “location” peoperties is for! – Can’t inhert from more than one base class in.NET! • So, what to do? – Dump fix. (Do Not Do it (DNDI) unlsess necessary)
  • 30. Multiple Inheritance - DNDI #pragma once using namespace System; namespace dotNet8_Inheir { ref class Form1; ref class MyClass : public System::Windows::Forms::Button { private: Form1 ^MyForm; System::Windows::Forms::ComboBox ^MyCB; public: MyClass(Form1 ^f); void InitializeButton(); void InitializeComboBox(System::Windows::Forms::ComboBox ^%); }; }
  • 31. #include "StdAfx.h" #include "MyClass.h” namespace dotNet8_Inheir { MyClass::MyClass(Form1 ^f) { MyForm = f; InitializeButton(); InitializeComboBox(MyCB); } void MyClass::InitializeButton() { this->Location = System::Drawing::Point(223, 121); this->Name = L"button1"; this->Size = System::Drawing::Size(75, 23); this->TabIndex = 0; this->Text = L"My Button!"; this->UseVisualStyleBackColor = true; } void MyClass::InitializeComboBox(System::Windows::Forms::ComboBox ^%CB) { CB = gcnew System::Windows::Forms::ComboBox; CB->Location = System::Drawing::Point(223, 121); CB->Size = System::Drawing::Size(75, 23); CB->TabIndex = 0; CB->Text = L"My ComboBox!"; CB->Parent = this; } }
  • 32.
  • 33. Multiple Inheritance - DNDI • Let’s start all over again private: System::Void Form1_Load(System::Object^ System::EventArgs^ e) { MyClass ^MC; MC = gcnew MyClass(this); } sender,
  • 34. Multiple Inheritance - DNDI #pragma once using namespace System; namespace dotNet8_Inheir { ref class Form1; ref class MyClass : public System::Windows::Forms::Button { private: Form1 ^MyForm; System::Windows::Forms::ComboBox ^MyCB; public: MyClass(Form1 ^f); void InitializeButton(); void InitializeComboBox(System::Windows::Forms::ComboBox ^%); void PlayIt(System::Object^ sender, System::EventArgs^ e); void comboBox1_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e); }; }
  • 35. #include "StdAfx.h" #include "MyClass.h" #include "Form1.h" namespace dotNet8_Inheir { MyClass::MyClass(Form1 ^f) { MyForm = f; this->Parent = MyForm; InitializeButton(); InitializeComboBox(MyCB); } void MyClass::InitializeButton() { this->Button::Location = System::Drawing::Point(223, 121); this->Name = L"button1"; this->Size = System::Drawing::Size(75, 23); this->TabIndex = 0; this->Text = L"My Button!"; this->UseVisualStyleBackColor = true; this->Click += gcnew System::EventHandler(this, &MyClass::PlayIt); }
  • 36. void MyClass::InitializeComboBox(System::Windows::Forms::ComboBox ^%CB) { CB = gcnew System::Windows::Forms::ComboBox; CB->FormattingEnabled = true; CB->Location = System::Drawing::Point(100, 100); CB->Size = System::Drawing::Size(121, 21); CB->TabIndex = 2; MyCB->Parent = MyClass::Parent; CB->SelectedIndexChanged += gcnew System::EventHandler(this, &MyClass::comboBox1_SelectedIndexChanged); } void MyClass::PlayIt(System::Object^ sender, System::EventArgs^ e) { Drawing::Point P = (dynamic_cast <Button^> (sender))->Location; MyCB->Location = P; } void MyClass::comboBox1_SelectedIndexChanged(System::Object^ System::EventArgs^ e) { } } sender,
  • 37. Multiple Inheritance - DNDI After pressing the button
  • 39. Go have some fun!