Array of Button like in C#

  • Thread starter Thread starter Picander
  • Start date Start date
P

Picander

Hello,

I need to create a form with multiple buttons instances. In C#, this
would look like this

static string[] strCaption={"Button A","Button B","Button C"};
Button[] btnShow=new Button[strCaption.Length];

for(int i=0 ; i < strCaption.Length ; i++)
{
btnShow=new Button();
btnShow.Text=strCaption;
btnShow.Size=new Size(200,20);
btnShow.Location=new Point(10,35*i+20);
btnShow.Click+=new EventHandler(Button_Click);
btnShow.Tag=i.ToString();
this.Controls.Add(btnShow);
}

I try to code this in C++, but I have a lot troubles setting the
identifiers.

This:
Button* btnShow[]
....
btnShow=new Button();
....

does not work. Any suggestions/code samples?

Thanks in advance,

Picander
 
Picander,
static string[] strCaption={"Button A","Button B","Button C"};
Button[] btnShow=new Button[strCaption.Length];

for(int i=0 ; i < strCaption.Length ; i++)
{
btnShow=new Button();
btnShow.Text=strCaption;
btnShow.Size=new Size(200,20);
btnShow.Location=new Point(10,35*i+20);
btnShow.Click+=new EventHandler(Button_Click);
btnShow.Tag=i.ToString();
this.Controls.Add(btnShow);
}

I try to code this in C++, but I have a lot troubles setting the
identifiers.

This:
Button* btnShow[]
...
btnShow=new Button();
...


You declared the array but never created it!

Try:
Button* btnShow[] = new Button*[strCaption->Length];
....
btnShow=new Button();
 
Back
Top