473,405 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Array of Button like in C#

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[i]=new Button();
btnShow[i].Text=strCaption[i];
btnShow[i].Size=new Size(200,20);
btnShow[i].Location=new Point(10,35*i+20);
btnShow[i].Click+=new EventHandler(Button_Click);
btnShow[i].Tag=i.ToString();
this.Controls.Add(btnShow[i]);
}

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

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

does not work. Any suggestions/code samples?

Thanks in advance,

Picander
Nov 17 '05 #1
1 862
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[i]=new Button();
btnShow[i].Text=strCaption[i];
btnShow[i].Size=new Size(200,20);
btnShow[i].Location=new Point(10,35*i+20);
btnShow[i].Click+=new EventHandler(Button_Click);
btnShow[i].Tag=i.ToString();
this.Controls.Add(btnShow[i]);
}

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

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


You declared the array but never created it!

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

--
Tomas Restrepo
to****@mvps.org
Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: John MacIntyre | last post by:
Hi, I have a page with a series of child pages loaded into an iframe. When I move from page to page, I store an object containing the child's control data in a variable on the main page, then...
4
by: Mark Hannon | last post by:
I am trying to initialize an array only once so it can be seen & used by any functions that need it. As I understand it, if a variable is declared by itself outside of any functions, its scope is...
13
by: Martin Altschwager | last post by:
Hi, I desperately need some help with what I assume to be a minor problem that I just can't solve. I'm writing a page where on mouseover a link, an image needs to be displayed and some text,...
3
by: gcl | last post by:
Hi, How to associate the dynamic controls array with its event? For example, creating a number of button, like 100, etc.. Button arrButton ..... In VB6, when u copy and paste a button
3
by: Pol Bawin | last post by:
Hi All, One : I have a property that get/set a array of an abstract class A By default my array is null In the propertygrid, It is not works correctly when my array is null. (when my array...
3
by: Newcomsas | last post by:
Hello, I'm trying to solve a problem with JS textbox array without success. I have two buttons in my page: PLUS and MINUS; at every click on PLUS a new textbox named 'dear' is generated. So, if...
6
by: loga123 | last post by:
I am using asp.net 2.0. I want to get the results of a sql query into an array at run-time. Number of records returned varies each time.....so I want to declare the dimensions of array runtime...
6
by: Chuck Anderson | last post by:
My knowledge of JavaScript is limited. I learn from example and then adapt those examples to suit my needs. I have stumped myself on this one. I have a form with checkboxes that I want to...
6
by: sgottenyc | last post by:
Hello, If you could assist me with the following situation, I would be very grateful. I have a table of data retrieved from database displayed on screen. To each row of data, I have added...
1
by: Nightfarer | last post by:
Hello. I have a big trouble using System.Array class (it's the first time I use it) for a software I'm developing. I have a form with a textbox(numbers) and one button (done). Once the number...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.