Click here to Skip to main content
15,923,376 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all
I want to have a global form for my program so I create a simple public form and then I inherit it in other form , my code is this :

C++
#pragma once
#include "Frm_Global.h"

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;



namespace MyNameSpace {

	public ref class Frm_Bill : public Frm_Global
	{
	public:
		Frm_Bill(void)
		{
			InitializeComponent();
		}

	public:
		~Frm_Bill()
		{
			if (components)
			{
				delete components;
			}
		}



	private:
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->SuspendLayout();
			// 
			// Frm_Bill
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(573, 367);
			this->Name = L"Frm_Bill";
			this->Text = L"Frm_Bill";
			this->ResumeLayout(false);

		}
#pragma endregion
	};
}

but can not load the Global Form in designer !
Posted
Updated 7-May-12 5:33am
v4
Comments
JackDingler 7-May-12 11:29am    
Moved from the C++ forum to C#
Sergey Alexandrovich Kryukov 7-May-12 12:33pm    
Not clear what do you mean by such loading and why would you need it.
--SA

1 solution

First note: the naming "Frm_Global" is pretty bad. Formally, it does not matter, but shows some misunderstanding. This form is no more "global" then any other form, this is just a form meant to be a base class for some other forms, nothing more.

Now, it's not clear what do you need to "load" in designer and why. Maybe, this is based on some misconception on what designer does. Let's overview the simplest steps. First, you create you class for you base form. If you do use using the designer, you can see work with it using the designer. You can also create this class as any other class, purely in code. This does not matter for further steps. Let's assume you name you base form as BaseForm.

Now, you want to create a derived form. If you create is without designed, you simply write code of it and specify the inheritance list for the class. First, if you do it in a separate class, you should add #include and include a header file where you declared the base form. (Many years I cannot help wondering how such archaic technique as "include" could survive by the end of XX and even in XXI century!) Then, you should specify the derived form like this public ref class FormBill : BaseForm { /* ... */ }; and be done. You can also work with the derived from using the designer, but then you should better create this form using the designer. In this case, the steps will be different. The designer will generate you the header file with inheritance list already in place, looking something like public ref class FormBill : public System::Windows::Forms::Form { /* ... */ }; you should, again, include the header file of the base form and modify the declaration replacing the base class the System::Windows::Forms::Form with BaseForm. In this case, you will see the control of both base and derived class with the designer of the derived form FormBill.

Likewise, you can inherit the forms defined by other .NET assemblies (no matter written in what .NET language). You should reference this assembly by the assembly where you define the derived form and qualify the base class fully, with namespace name. (Actually, you may need to qualify the names with full or partial namespaces in all cases, not matter how the classes are placed in assembly, as you can use different namespaces in the same assembly and share identical namespaces across assemblies.)

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900