DataGridTextBoxColumn.Paint Method

Definition

Paints the column in the DataGrid control.

Overloads

Paint(Graphics, Rectangle, CurrencyManager, Int32)

Paints the a DataGridColumnStyle with the specified Graphics, Rectangle, CurrencyManager, and row number.

C#
protected internal override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager source, int rowNum);

Parameters

g
Graphics

The Graphics object to draw to.

bounds
Rectangle

The bounding Rectangle to paint into.

source
CurrencyManager

The CurrencyManager of the DataGrid the that contains the column.

rowNum
Int32

The number of the row in the underlying data table.

See also

Applies to

.NET Framework 4.8.1 y otras versiones
Producto Versiones
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 10

Paint(Graphics, Rectangle, CurrencyManager, Int32, Boolean)

Paints a DataGridColumnStyle with the specified Graphics, Rectangle, CurrencyManager, row number, and alignment.

C#
protected internal override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager source, int rowNum, bool alignToRight);

Parameters

g
Graphics

The Graphics object to draw to.

bounds
Rectangle

The bounding Rectangle to paint into.

source
CurrencyManager

The CurrencyManager of the DataGrid the that contains the column.

rowNum
Int32

The number of the row in the underlying data table.

alignToRight
Boolean

A value indicating whether to align the column's content to the right. true if the content should be aligned to the right; otherwise, false.

Remarks

The Paint method uses the GetColumnValueAtRow to determine the value to draw in the cell. The PaintText method is called to draw the cell and its contents.

See also

Applies to

.NET Framework 4.8.1 y otras versiones
Producto Versiones
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 10

Paint(Graphics, Rectangle, CurrencyManager, Int32, Brush, Brush, Boolean)

Paints a DataGridColumnStyle with the specified Graphics, Rectangle, CurrencyManager, row number, Brush, and foreground color.

C#
protected internal override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush, bool alignToRight);

Parameters

g
Graphics

The Graphics object to draw to.

bounds
Rectangle

The bounding Rectangle to paint into.

source
CurrencyManager

The CurrencyManager of the DataGrid the that contains the column.

rowNum
Int32

The number of the row in the underlying data table.

backBrush
Brush

A Brush that paints the background.

foreBrush
Brush

A Brush that paints the foreground color.

alignToRight
Boolean

A value indicating whether to align the column's content to the right. true if the content should be aligned to the right; otherwise, false.

Examples

The following example uses the Paint method to paint a clicked cell with new foreground and background color.

C#
public class Form1: Form
{
 protected DataGrid dataGrid1;
 protected DataSet myDataSet;

private void PaintCell(object sender, MouseEventArgs e)
{
    // Use the HitTest method to get a HitTestInfo object.
    DataGrid.HitTestInfo hi;
    DataGrid grid = (DataGrid)sender;
    hi=grid.HitTest(e.X, e.Y);
    // Test if the clicked area was a cell.
    if(hi.Type == DataGrid.HitTestType.Cell)
    {
       // If it's a cell, get the GridTable and ListManager of the
       // clicked table.         
       DataGridTableStyle dgt = dataGrid1.TableStyles[0];
       CurrencyManager cm = (CurrencyManager)this.BindingContext[myDataSet.Tables[dgt.MappingName]];
       // Get the Rectangle of the clicked cell.
       Rectangle cellRect;
       cellRect=grid.GetCellBounds(hi.Row, hi.Column);
       // Get the clicked DataGridTextBoxColumn.
       MyGridColumn  gridCol =(MyGridColumn)dgt.GridColumnStyles[hi.Column];
       // Get the Graphics object for the form.
       Graphics g = dataGrid1.CreateGraphics();
       // Create two new Brush objects, a fore brush, and back brush.
       Brush fBrush = new System.Drawing.SolidBrush(Color.Blue);
       Brush bBrush= new System.Drawing.SolidBrush(Color.Yellow);
       // Invoke the Paint method to paint the cell with the brushes.
       gridCol.PaintCol(g, cellRect, cm, hi.Row, bBrush, fBrush, false);
     }
 }
}

public class MyGridColumn:DataGridTextBoxColumn{
   public void PaintCol(Graphics g, Rectangle cellRect, 
    CurrencyManager cm, int rowNum, Brush bBrush, 
    Brush fBrush, bool isVisible){
      this.Paint(g, cellRect, cm, rowNum, bBrush, fBrush, isVisible);
   }
}

Remarks

The Paint method uses the GetColumnValueAtRow to determine the value to draw in the cell. The PaintText method is called to draw the cell and its contents.

See also

Applies to

.NET Framework 4.8.1 y otras versiones
Producto Versiones
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0