次の方法で共有


DataGridTextBoxColumn.Paint メソッド

このメンバは、.NET Framework インフラストラクチャのサポートを目的としています。独自に作成したコード内で直接使用することはできません。

オーバーロードの一覧

このメンバは DataGridColumnStyle.Paint をオーバーライドします。

[Visual Basic] Overloads Protected Friend Overrides Sub Paint(Graphics, Rectangle, CurrencyManager, Integer)

[C#] protected internal override void Paint(Graphics, Rectangle, CurrencyManager, int);

[C++] protected public: void Paint(Graphics*, Rectangle, CurrencyManager*, int);

[JScript] protected internal override function Paint(Graphics, Rectangle, CurrencyManager, int);

このメンバは DataGridColumnStyle.Paint をオーバーライドします。

[Visual Basic] Overloads Protected Friend Overrides Sub Paint(Graphics, Rectangle, CurrencyManager, Integer, Boolean)

[C#] protected internal override void Paint(Graphics, Rectangle, CurrencyManager, int, bool);

[C++] protected public: void Paint(Graphics*, Rectangle, CurrencyManager*, int, bool);

[JScript] protected internal override function Paint(Graphics, Rectangle, CurrencyManager, int, Boolean);

このメンバは DataGridColumnStyle.Paint をオーバーライドします。

[Visual Basic] Overloads Protected Friend Overrides Sub Paint(Graphics, Rectangle, CurrencyManager, Integer, Brush, Brush, Boolean)

[C#] protected internal override void Paint(Graphics, Rectangle, CurrencyManager, int, Brush, Brush, bool);

[C++] protected public: void Paint(Graphics*, Rectangle, CurrencyManager*, int, Brush*, Brush*, bool);

[JScript] protected internal override function Paint(Graphics, Rectangle, CurrencyManager, int, Brush, Brush, Boolean);

使用例

[Visual Basic, C#, C++] The following example uses the Paint method to paint a clicked cell with new foreground and background color.

[Visual Basic, C#, C++] メモ   ここでは、Paint のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。

 
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 'PaintCell
End Class 'Form1 

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

[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);
   }
}

[C++] 
public __gc 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 __gc 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->Item[0];
       CurrencyManager* cm = dynamic_cast<CurrencyManager*>
          (this->BindingContext->Item[myDataSet->Tables->Item[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->Item[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);
     }
 }
};

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

参照

DataGridTextBoxColumn クラス | DataGridTextBoxColumn メンバ | System.Windows.Forms 名前空間