G
Guest
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.EventHandler(ClickHandler);
aButton.Width=50;
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.Add(aButton);
}
}
private void ClickHandler(object sender, System.EventArgs e)
{
MessageBox.Show("Button" +((Button) sender).Tag.ToString() + " was
clicked");
}
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.EventHandler(ClickHandler);
aButton.Width=50;
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.Add(aButton);
}
}
private void ClickHandler(object sender, System.EventArgs e)
{
MessageBox.Show("Button" +((Button) sender).Tag.ToString() + " was
clicked");
}