-
May 18th, 2009, 12:22 PM
#1
How to create n no of buttons dynamically and handle their events?
please send ur suggestions regarding this topic
-
May 18th, 2009, 01:45 PM
#2
Re: How to create n no of buttons dynamically and handle their events?
It's pretty basic...
Code:
for ( int i = 0; i < n; ++i)
{
Button button = new Button( );
// set properties like "Location"...
button.Click += button_Click;
// assuming the "this" pointer is the parent of the controls.
this.Controls.Add( button );
}
private void button_Click( object sender, EventArgs e )
{
// handle the click event for each button here
}
Last edited by BigEd781; May 19th, 2009 at 04:05 PM.
-
May 19th, 2009, 02:01 AM
#3
Re: How to create n no of buttons dynamically and handle their events?
Originally Posted by BigEd781
Code:
private void button_Click(EventArgs e)
{
// handle the click event for each button here
}
Shouldn't it be
Code:
private void button_Click(object sender, EventArgs e)
{
// handle the click event for each button here
}
-
May 19th, 2009, 04:05 PM
#4
Re: How to create n no of buttons dynamically and handle their events?
Originally Posted by dannystommen
Shouldn't it be
Code:
private void button_Click(object sender, EventArgs e)
{
// handle the click event for each button here
}
Yes, it should
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
|