|
-
Apr 24th, 2005, 08:14 AM
#1
Thread Starter
Addicted Member
overcomming Control Arrays
Hello everybody,
I come from a pretty colorful VB6 background and am now trying to learn C#.
all goes pretty well for me except for the fact that there are no control arrays(correct me if I'm wrong).
I've created a grid of command buttons at runtime, linked their click event to the same delegate and all, but now I can'f figure out how to retrieve the index of a button, (3,4) for example....
it would serve my purpose perfectly well if I could create an array and link each button to an entry, but I would like to hear other ideas on the subject(how to overcome the obstacles that resulted from dropping array controls)
please don't tell me to put the index into the Tag property of each button...
Thanks in advance
-
Apr 24th, 2005, 08:44 PM
#2
Fanatic Member
Re: overcomming Control Arrays
Is this something you need?
VB Code:
private void Form1_Load(object sender, System.EventArgs e)
{
int y=10;
for(int i=0;i<10;i++)
{
Button b=new Button();
b.Text="Button"+i.ToString();
b.Location=new Point(10,y);
b.Click+=new EventHandler(b_Click);
this.Controls.Add(b);
y+=25;
}
}
void b_Click(object sender,EventArgs e)
{
Button b=(Button)sender;
MessageBox.Show(b.TabIndex.ToString());
}
Or I am missing something. If so, I am sorry... but if you need something from the sender, you can actually do anything on the b variable under the b_Click function. Hopefully this helps.
-
Apr 25th, 2005, 08:44 AM
#3
Thread Starter
Addicted Member
Re: overcomming Control Arrays
Thank you Mokey,
it's the "this.Controls.Add(b);" line that I've been missing... Thank you for helping me out on this one.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|