private void tableLayoutPanel1_MouseClick(object sender, MouseEventArgs e) { int row = 0; int verticalOffset = 0; Graphics surface = this.CreateGraphics(); Pen p = new Pen(System.Drawing.Color.Turquoise,5); foreach (int h in tableLayoutPanel1.GetRowHeights()) { int column = 0; int horizontalOffset = 0; foreach (int w in tableLayoutPanel1.GetColumnWidths()) { Rectangle rectangle = new Rectangle(horizontalOffset, verticalOffset, w, h); //surface.DrawRectangle(p, rectangle); if (rectangle.Contains(e.Location)) { surface.DrawRectangle(p, rectangle); SolidBrush myBrush=new SolidBrush(Color.Pink); surface.FillRectangle(myBrush, rectangle); tableLayoutPanel1.SendToBack(); MessageBox.Show(String.Format("row {0}, column {1} was clicked", row, column)); return; } horizontalOffset += w; column++; } verticalOffset += h; row++; } }
this.CreateGraphics
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)