Here's a step by step of my process in imitating the procedure found on that site. This should allow someone else to view what mistakes I'm making.
1. Open a new project under VC++ -->.NET-->>.NET Empty Project, name application ButtonArrayProject.
2. Add class by going to the Project Menu and selecting VC++ -->Generic-->Generic C++ Class
name = ButtonArray
base class = System::Collections::CollectionBase
access = public
I currently only have a header file "ButtonArray.h."
3. Add code to start class
- public __gc class ButtonArray : public System::Collections::CollectionBase
-
{
-
// Public Class ButtonArray
-
}
Build solution real quick to make sure everything is ok.
4. Add code for private form reference
- public __gc class ButtonArray : public System::Collections::CollectionBase
-
{
-
// Public Class ButtonArray
-
-
private: System::Windows::Forms::Form HostForm;
-
}
5. Add code for AddNewButton method
- public __gc class ButtonArray : public System::Collections::CollectionBase
-
{
-
// Public Class ButtonArray
-
-
private: System::Windows::Forms::Form *HostForm;
-
-
public: System::Windows::Forms::Button *AddNewButton(void)
-
{
-
//Create New Instance of Button Class
-
System::Windows::Forms::Button *aButton = new System::Windows::Forms::Button();
-
-
//Add new button to collection's list
-
this->List->Add(aButton);
-
-
//Add the button to the controls collection of the form referenced by the HostForm field.
-
HostForm->Controls->Add(aButton);
-
-
//Set Initial properties for the button object.
-
aButton->Top = Count + 25;
-
aButton->Left = 100;
-
aButton->Tag = this->Count;
-
aButton->Text = String.Concat("Button ", this->Count.ToString());
-
-
return aButton;
-
}
-
}
I'll stop here, because I obviously have some syntax errors already. The code builds fine, but that means nothing because nothing's using it yet.
- iknc4miles