I created a control array at runtime using the following code. I also wanted
to code the controlarray click event. My code can respond to click event
but cannot identify the specific control clicked on, which is important to my
application.
Appreciate your help.
Frank
---------------------------
private void initBoard()
{
this.Width=250;
this.Height=250 ;
buttonArray = new Button[4,4];
for (int i = 1; i<=3; i++)
for (int j=1; j<=3;j++)
{
Button aButton = new Button();
aButton.Click += new System.EventHan dler(ClickHandl er);
aButton.Width=5 0;
aButton.Height= 50;
aButton.Top = i * 50;
aButton.Left = j*50;
buttonArray[i,j]=aButton;
// Add the button to the controls collection of the form
this.Controls.A dd(aButton);
}
}
private void ClickHandler(ob ject sender, System.EventArg s e)
{
MessageBox.Show ("Button" +((Button) sender).Tag.ToS tring() + " was
clicked");
}
--
Frank
to code the controlarray click event. My code can respond to click event
but cannot identify the specific control clicked on, which is important to my
application.
Appreciate your help.
Frank
---------------------------
private void initBoard()
{
this.Width=250;
this.Height=250 ;
buttonArray = new Button[4,4];
for (int i = 1; i<=3; i++)
for (int j=1; j<=3;j++)
{
Button aButton = new Button();
aButton.Click += new System.EventHan dler(ClickHandl er);
aButton.Width=5 0;
aButton.Height= 50;
aButton.Top = i * 50;
aButton.Left = j*50;
buttonArray[i,j]=aButton;
// Add the button to the controls collection of the form
this.Controls.A dd(aButton);
}
}
private void ClickHandler(ob ject sender, System.EventArg s e)
{
MessageBox.Show ("Button" +((Button) sender).Tag.ToS tring() + " was
clicked");
}
--
Frank
Comment