次の方法で共有


DataGridTextBoxColumn.Paint メソッド

定義

DataGrid コントロールの列を描画します。

オーバーロード

Paint(Graphics, Rectangle, CurrencyManager, Int32)

指定した DataGridColumnStyleGraphicsRectangle、および行番号を使用して CurrencyManager を描画します。

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

指定した DataGridColumnStyleGraphicsRectangle、行番号、および配置を使用して CurrencyManager を描画します。

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

指定した DataGridColumnStyleGraphicsRectangle、行番号、CurrencyManager、および前景色を使用して Brush を描画します。

Paint(Graphics, Rectangle, CurrencyManager, Int32)

指定した DataGridColumnStyleGraphicsRectangle、および行番号を使用して CurrencyManager を描画します。

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 オブジェクト。

bounds
Rectangle

描画範囲の外接する Rectangle

source
CurrencyManager

列を格納している CurrencyManagerDataGrid

rowNum
Int32

基になるデータ テーブルにある行の番号。

こちらもご覧ください

適用対象

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

指定した DataGridColumnStyleGraphicsRectangle、行番号、および配置を使用して CurrencyManager を描画します。

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 オブジェクト。

bounds
Rectangle

描画範囲の外接する Rectangle

source
CurrencyManager

列を格納している CurrencyManagerDataGrid

rowNum
Int32

基になるデータ テーブルにある行の番号。

alignToRight
Boolean

列の内容を右側に配置するかどうかを示す値。 内容を右側に配置する必要がある場合は true。それ以外の場合は false

注釈

このメソッドを Paint 使用 GetColumnValueAtRow して、セルに描画する値を決定します。 この PaintText メソッドは、セルとその内容を描画するために呼び出されます。

こちらもご覧ください

適用対象

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

指定した DataGridColumnStyleGraphicsRectangle、行番号、CurrencyManager、および前景色を使用して Brush を描画します。

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 オブジェクト。

bounds
Rectangle

描画範囲の外接する Rectangle

source
CurrencyManager

列を格納している CurrencyManagerDataGrid

rowNum
Int32

基になるデータ テーブルにある行の番号。

backBrush
Brush

背景を描画する Brush

foreBrush
Brush

前景色を描画する Brush

alignToRight
Boolean

列の内容を右側に配置するかどうかを示す値。 内容を右側に配置する必要がある場合は true。それ以外の場合は false

次の例では、このメソッドを Paint 使用して、クリックされたセルを新しい前景色と背景色で描画します。

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 して、セルに描画する値を決定します。 この PaintText メソッドは、セルとその内容を描画するために呼び出されます。

こちらもご覧ください

適用対象