This document discusses inheritance and multiple inheritance in C++.NET Windows Forms. It shows how to inherit from a Button class to create a custom button that can set its own text and location. It then demonstrates how to inherit from multiple classes is not supported, and provides a workaround using composition instead of inheritance to combine the functionality of a Button and ComboBox within a single custom class. The class initializes the button properties and adds event handlers, and also initializes a composed ComboBox and sets its location based on button clicks.
6. Inheritance
• Now, let’s have the following class:
#pragma once
using namespace::System;
ref class MyClass
{
public:
MyClass(void);
virtual String ^ToString() override;
};
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;
};
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 ^%);
};
}