DataGridTextBoxColumn.Paint 方法

定义

DataGrid 控件中绘制此列。Paints the column in the DataGrid control.

重载

Paint(Graphics, Rectangle, CurrencyManager, Int32)

绘制具有指定 DataGridColumnStyleGraphicsRectangle 和行号的 CurrencyManagerPaints the a DataGridColumnStyle with the specified Graphics, Rectangle, CurrencyManager, and row number.

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

绘制具有指定 DataGridColumnStyleGraphicsRectangle、行号和对齐方式的 CurrencyManagerPaints a DataGridColumnStyle with the specified Graphics, Rectangle, CurrencyManager, row number, and alignment.

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

绘制具有指定 DataGridColumnStyleGraphicsRectangle、行号、CurrencyManager 和前景色的 BrushPaints a DataGridColumnStyle with the specified Graphics, Rectangle, CurrencyManager, row number, Brush, and foreground color.

Paint(Graphics, Rectangle, CurrencyManager, Int32)

绘制具有指定 DataGridColumnStyleGraphicsRectangle 和行号的 CurrencyManagerPaints the a DataGridColumnStyle with the specified Graphics, Rectangle, CurrencyManager, and row number.

protected public:
 override void Paint(System::Drawing::Graphics ^ g, System::Drawing::Rectangle bounds, System::Windows::Forms::CurrencyManager ^ source, int rowNum);
protected internal override void Paint (System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager source, int rowNum);
override this.Paint : System.Drawing.Graphics * System.Drawing.Rectangle * System.Windows.Forms.CurrencyManager * int -> unit
Protected Friend Overrides Sub Paint (g As Graphics, bounds As Rectangle, source As CurrencyManager, rowNum As Integer)

参数

g
Graphics

Graphics 对象,要向该对象进行绘制。The Graphics object to draw to.

bounds
Rectangle

要在其中绘画的外围 RectangleThe bounding Rectangle to paint into.

source
CurrencyManager

包含该列的 CurrencyManagerDataGridThe CurrencyManager of the DataGrid the that contains the column.

rowNum
Int32

该行在基础数据表中的编号。The number of the row in the underlying data table.

另请参阅

适用于

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

绘制具有指定 DataGridColumnStyleGraphicsRectangle、行号和对齐方式的 CurrencyManagerPaints a DataGridColumnStyle with the specified Graphics, Rectangle, CurrencyManager, row number, and alignment.

protected public:
 override void Paint(System::Drawing::Graphics ^ g, System::Drawing::Rectangle bounds, System::Windows::Forms::CurrencyManager ^ source, int rowNum, bool alignToRight);
protected internal override void Paint (System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager source, int rowNum, bool alignToRight);
override this.Paint : System.Drawing.Graphics * System.Drawing.Rectangle * System.Windows.Forms.CurrencyManager * int * bool -> unit
Protected Friend Overrides Sub Paint (g As Graphics, bounds As Rectangle, source As CurrencyManager, rowNum As Integer, alignToRight As Boolean)

参数

g
Graphics

Graphics 对象,要向该对象进行绘制。The Graphics object to draw to.

bounds
Rectangle

要在其中绘画的外围 RectangleThe bounding Rectangle to paint into.

source
CurrencyManager

包含该列的 CurrencyManagerDataGridThe 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;否则为 falsetrue if the content should be aligned to the right; otherwise, false.

注解

Paint方法使用 GetColumnValueAtRow 来确定要在单元格中绘制的值。The Paint method uses the GetColumnValueAtRow to determine the value to draw in the cell. PaintText调用方法来绘制单元格及其内容。The PaintText method is called to draw the cell and its contents.

另请参阅

适用于

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

绘制具有指定 DataGridColumnStyleGraphicsRectangle、行号、CurrencyManager 和前景色的 BrushPaints a DataGridColumnStyle with the specified Graphics, Rectangle, CurrencyManager, row number, Brush, and foreground color.

protected public:
 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);
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);
override this.Paint : System.Drawing.Graphics * System.Drawing.Rectangle * System.Windows.Forms.CurrencyManager * int * System.Drawing.Brush * System.Drawing.Brush * bool -> unit
Protected Friend Overrides Sub Paint (g As Graphics, bounds As Rectangle, source As CurrencyManager, rowNum As Integer, backBrush As Brush, foreBrush As Brush, alignToRight As Boolean)

参数

g
Graphics

Graphics 对象,要向该对象进行绘制。The Graphics object to draw to.

bounds
Rectangle

要在其中绘画的外围 RectangleThe bounding Rectangle to paint into.

source
CurrencyManager

包含该列的 CurrencyManagerDataGridThe CurrencyManager of the DataGrid the that contains the column.

rowNum
Int32

该行在基础数据表中的编号。The number of the row in the underlying data table.

backBrush
Brush

一个 Brush,用来绘制背景。A Brush that paints the background.

foreBrush
Brush

一个 Brush,用来绘制前景色。A Brush that paints the foreground color.

alignToRight
Boolean

一个值,它指示该列的内容是否为右对齐。A value indicating whether to align the column's content to the right. 如果内容应为右对齐,则为 true;否则为 falsetrue if the content should be aligned to the right; otherwise, false.

示例

下面的示例使用 Paint 方法来绘制具有新的前景色和背景色的已单击的单元格。The following example uses the Paint method to paint a clicked cell with new foreground and background color.

public ref class MyGridColumn: public 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 );
   }

};

public ref class Form1: public Form
{
protected:
   DataGrid^ dataGrid1;
   DataSet^ myDataSet;

private:
   void PaintCell( Object^ sender, MouseEventArgs^ e )
   {
      
      // Use the HitTest method to get a HitTestInfo object.
      DataGrid::HitTestInfo ^ hi;
      DataGrid^ grid = dynamic_cast<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 = dynamic_cast<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 = dynamic_cast<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 = gcnew System::Drawing::SolidBrush( Color::Blue );
         Brush^ bBrush = gcnew 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 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);
   }
}
Public Class Form1
   Inherits Form
   Protected dataGrid1 As DataGrid
   Protected myDataSet As DataSet
    
   Private Sub PaintCell(sender As Object, e As MouseEventArgs)
      ' Use the HitTest method to get a HitTestInfo object.
      Dim hi As DataGrid.HitTestInfo
      Dim grid As DataGrid = CType(sender, DataGrid)
      hi = grid.HitTest(e.X, e.Y)
      ' Test if the clicked area was a cell.
      If hi.Type = DataGrid.HitTestType.Cell Then
         ' If it's a cell, get the GridTable and ListManager of the
         ' clicked table.         
         Dim dgt As DataGridTableStyle = dataGrid1.TableStyles(0)
         Dim cm As CurrencyManager = CType(Me.BindingContext _
         (myDataSet.Tables(dgt.MappingName)), CurrencyManager)
         ' Get the Rectangle of the clicked cell.
         Dim cellRect As Rectangle
         cellRect = grid.GetCellBounds(hi.Row, hi.Column)
         ' Get the clicked DataGridTextBoxColumn.
         Dim gridCol As MyGridColumn = CType _
         (dgt.GridColumnStyles(hi.Column), MyGridColumn)
         ' Get the Graphics object for the form.
         Dim g As Graphics = dataGrid1.CreateGraphics()
         ' Create two new Brush objects: a fore brush and back brush.
         Dim fBrush As New SolidBrush(Color.Blue)
         Dim bBrush As New SolidBrush(Color.Yellow)
         ' Invoke the Paint method to paint the cell with the brushes.
         gridCol.PaintCol(g, cellRect, cm, hi.Row, bBrush, fBrush, False)
      End If
   End Sub
End Class

Public Class MyGridColumn
Inherits DataGridTextBoxColumn
   Public Sub PaintCol(g As Graphics , cellRect As Rectangle , _
      cm As CurrencyManager , rowNum As integer , bBrush as Brush , _
      fBrush As Brush , isVisible As Boolean )
      me.Paint(g, cellRect, cm, rowNum, bBrush, fBrush, isVisible)
   End Sub
End Class

注解

Paint方法使用 GetColumnValueAtRow 来确定要在单元格中绘制的值。The Paint method uses the GetColumnValueAtRow to determine the value to draw in the cell. PaintText调用方法来绘制单元格及其内容。The PaintText method is called to draw the cell and its contents.

另请参阅

适用于