DataGridViewCellPaintingEventArgs-Klasse
Assembly: System.Windows.Forms (in system.windows.forms.dll)
Das CellPainting-Ereignis wird für jede DataGridViewCell ausgelöst, die in einer DataGridView angezeigt wird. Legen Sie zum Erzielen einer höheren Leistung anstatt direkt auf eine Zelle in der DataGridView zuzugreifen, die Eigenschaften in DataGridViewCellPaintingEventArgs so fest, dass die Darstellung einer Zelle geändert wird. Wenn Sie die Zelle manuell zeichnen, legen Sie die HandledEventArgs.Handled-Eigenschaft auf true fest. Wenn Sie HandledEventArgs.Handled nicht auf true festlegen, zeichnet die Zelle über die von Ihnen vorgenommenen Anpassungen.
Im folgenden Codebeispiel wird die Verwendung dieses Typs veranschaulicht. Weitere Informationen finden Sie unter Gewusst wie: Anpassen der Darstellung von Zellen im DataGridView-Steuerelement von Windows Forms.
private void dataGridView1_CellPainting(object sender, System.Windows.Forms.DataGridViewCellPaintingEventArgs e) { if (this.dataGridView1.Columns["ContactName"].Index == e.ColumnIndex && e.RowIndex >= 0) { Rectangle newRect = new Rectangle(e.CellBounds.X + 1, e.CellBounds.Y + 1, e.CellBounds.Width - 4, e.CellBounds.Height - 4); using ( Brush gridBrush = new SolidBrush(this.dataGridView1.GridColor), backColorBrush = new SolidBrush(e.CellStyle.BackColor)) { using (Pen gridLinePen = new Pen(gridBrush)) { // Erase the cell. e.Graphics.FillRectangle(backColorBrush, e.CellBounds); // Draw the grid lines (only the right and bottom lines; // DataGridView takes care of the others). e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, e.CellBounds.Bottom - 1, e.CellBounds.Right - 1, e.CellBounds.Bottom - 1); e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1, e.CellBounds.Top, e.CellBounds.Right - 1, e.CellBounds.Bottom); // Draw the inset highlight box. e.Graphics.DrawRectangle(Pens.Blue, newRect); // Draw the text content of the cell, ignoring alignment. if (e.Value != null) { e.Graphics.DrawString((String)e.Value, e.CellStyle.Font, Brushes.Crimson, e.CellBounds.X + 2, e.CellBounds.Y + 2, StringFormat.GenericDefault); } e.Handled = true; } } } }
System.EventArgs
System.ComponentModel.HandledEventArgs
System.Windows.Forms.DataGridViewCellPaintingEventArgs
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.