Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Row/Column coloring for TableLayoutPanel (vs2008, winform)

Can i add particular color for entire Row or Column in TableLayoutPanel ? How ? please provide sample code if any ..

Thanks in adv.

like image 289
gauravghodnadikar Avatar asked Jan 09 '10 04:01

gauravghodnadikar


1 Answers

Yes you can.

Use the TableLayoutPanel's CellPaint event to test for which row/column has called the event and then use a Graphic object size to the rectangle to set the cell's color.

Like this (for the first and third rows):

     private void Form_Load(object sender, EventArgs e) {
        this.tableLayoutPanel1.CellPaint += new TableLayoutCellPaintEventHandler(tableLayoutPanel1_CellPaint);
     }


    void tableLayoutPanel1_CellPaint(object sender, TableLayoutCellPaintEventArgs e)
    {
        if (e.Row == 0 || e.Row == 2) {
            Graphics g = e.Graphics;
            Rectangle r = e.CellBounds;
            g.FillRectangle(Brushes.Blue, r);
        }
    }
like image 71
Jay Riggs Avatar answered Nov 03 '22 02:11

Jay Riggs