Ejemplo n.º 1
0
        private void tableLayoutPanel1_CellPaint(object sender, TableLayoutCellPaintEventArgs e)
        {
            e.Dispose();
            if (table_color[e.Column, e.Row] == 1)
            {
                e.Graphics.FillRectangle(Brushes.ForestGreen, e.CellBounds);
            }

            else
            {
                e.Graphics.FillRectangle(Brushes.Maroon, e.CellBounds);
            }
        }
 /// <summary>
 /// Replace usage of Invalidate because we need only the cell paint, not redraw the whole control.
 /// </summary>
 /// <param name="column"></param>
 /// <param name="row"></param>
 protected void RedrawCell(int column, int row)
 {
     using (Graphics gr = this.CreateGraphics())
     {
         int[] cellWidths = this.GetColumnWidths();
         int   _left = 0, _top = 0;
         for (int i = 0; i < column; i++)
         {
             _left += cellWidths[i];
         }
         int[] cellHeights = this.GetRowHeights();
         for (int i = 0; i < row; i++)
         {
             _top += cellHeights[i];
         }
         int       cellwidth  = cellWidths[column];
         int       cellheight = cellHeights[row];
         Rectangle newRect    = new Rectangle(_left, _top, cellwidth, cellheight);
         TableLayoutCellPaintEventArgs theevent = new TableLayoutCellPaintEventArgs(gr, newRect, newRect, column, row);
         this.OnCellPaint(theevent);
         theevent.Dispose();
     }
 }