SlideShare ist ein Scribd-Unternehmen logo
1 von 39
Downloaden Sie, um offline zu lesen
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!

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.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
 

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
 
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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

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
 
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
 

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

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
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 Scriptwesley chun
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
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...Martijn de Jong
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
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 WorkerThousandEyes
 
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...Drew Madelung
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
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 AutomationSafe Software
 
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 2024The Digital Insurer
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
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 TerraformAndrey Devyatkin
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
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...apidays
 

Kürzlich hochgeladen (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
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
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
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...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 
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...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
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
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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...
 

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!