Control Array

07/06/2009 15:25 Mankana#1
Hi, I want to rewrite one of my old projects in VS2008 using the C++ CLR.

It contains alot of Controls like Buttons, Combo Boxes ect... and i want

to create a Control Array for it. I already searched a few hours for a solution,

but i didn't found any 100% working solution.

I have added the following to my constructor code:

Code:
array<System::Windows::Forms::Button^>^test = gcnew array<System::Windows::Forms::Button^>(2);
			test[0] = (gcnew System::Windows::Forms::Button());
			test[0]->Location = System::Drawing::Point(100, 100);
			test[0]->Size = System::Drawing::Size(40, 40);
			test[0]->Text = L"M";
			test[0]->Visible = true;
			this->Controls->Add(test[0]);
So far, it create the button and i can see it. The problem is that Iam not

able to access the Object out of this code, so its some kind of local (if I
try to read informations, the debugger say undeclared variable.....)

Would be nice if someone could help me.

Thats the whole code:

07/10/2009 20:02 x]vIrus[x#2
your problem is that you declare the array in the init of form1,.. so if the init is done, the array is lost, the reference to the button is still in the form, so it wont disappear, if you declare the array out of the funktion, initialize the array in the function, then you can use it anywhere with test[x]->bla

simple example:

Fail:
Code:
void bla() { int blubb = 17; }
void blaa() { blubb=3; }
success:
Code:
int blubb;
void bla() { blubb=17; }
void blaa() { blubb=3; }
07/10/2009 20:53 Mankana#3
I already got a work around, just created the specific amount of controls and access them
over the index, but thanks for your answer
07/10/2009 21:15 x]vIrus[x#4
then see it as a future help, since this is the basics of the basics ;)
07/11/2011 06:23 suryaprasath#5
public static [Only registered and activated users can see links. Click Here To Register...] BlockCopy(
Array src,
int srcOffset,
Array dst,
int dstOffset,
int count )