1

I have a tableLayoutPanel in a form. There are 10 rows and 10 columns in tableLayoutPanel. Each cell contains a button. So there are 100 buttons. When a user clicks on any of the button I want to change the backcolor of that. Particular cell. How can I achieve this?

4

1 回答 1

4

TableLayoutPanel's cell does not have a property to control background color. Instead, you can put a panel on it, which would in turn host your button. Assuming your buttons are dynamically created and a generic handler is attached to every one of them, the following code will change back color of the panel when the button it hosts is clicked:

Private Sub Button_Click(sender As System.Object, e As System.EventArgs)
  CType(sender, Control).Parent.BackColor = Color.Black
End Sub
于 2013-05-23T13:56:03.733 回答