DataGridViewCellPaintingEventArgs Classe
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Fornisce i dati per l'evento CellPainting.
public ref class DataGridViewCellPaintingEventArgs : System::ComponentModel::HandledEventArgs
public class DataGridViewCellPaintingEventArgs : System.ComponentModel.HandledEventArgs
type DataGridViewCellPaintingEventArgs = class
inherit HandledEventArgs
Public Class DataGridViewCellPaintingEventArgs
Inherits HandledEventArgs
- Ereditarietà
Nell'esempio di codice seguente viene illustrato l'uso di questo tipo. Per altre informazioni, vedere Procedura: Personalizzare l'aspetto delle celle nel controllo DataGridView 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;
}
}
}
}
Private Sub dataGridView1_CellPainting(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) _
Handles dataGridView1.CellPainting
If Me.dataGridView1.Columns("ContactName").Index = _
e.ColumnIndex AndAlso e.RowIndex >= 0 Then
Dim newRect As New Rectangle(e.CellBounds.X + 1, e.CellBounds.Y + 1, _
e.CellBounds.Width - 4, e.CellBounds.Height - 4)
Dim backColorBrush As New SolidBrush(e.CellStyle.BackColor)
Dim gridBrush As New SolidBrush(Me.dataGridView1.GridColor)
Dim gridLinePen As New Pen(gridBrush)
Try
' 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 IsNot Nothing) Then
e.Graphics.DrawString(CStr(e.Value), e.CellStyle.Font, _
Brushes.Crimson, e.CellBounds.X + 2, e.CellBounds.Y + 2, _
StringFormat.GenericDefault)
End If
e.Handled = True
Finally
gridLinePen.Dispose()
gridBrush.Dispose()
backColorBrush.Dispose()
End Try
End If
End Sub
L'evento CellPainting viene generato per ogni DataGridViewCell oggetto visibile in un DataGridViewoggetto . Per migliorare le prestazioni, impostare le proprietà in un DataGridViewCellPaintingEventArgs per modificare l'aspetto della cella anziché accedere direttamente a una cella in DataGridView. Se si dipinge manualmente la cella, impostare la HandledEventArgs.Handled proprietà su true
. Se non si imposta HandledEventArgs.Handled su true
, la cella dipingerà le personalizzazioni.
Advanced |
Ottiene lo stile del bordo del controllo DataGridViewCell corrente. |
Cell |
Ottiene i limiti del controllo DataGridViewCell corrente. |
Cell |
Ottiene lo stile della cella del controllo DataGridViewCell corrente. |
Clip |
Ottiene l'area del controllo DataGridView da ridisegnare. |
Column |
Ottiene l'indice della colonna del controllo DataGridViewCell corrente. |
Error |
Ottiene una stringa che rappresenta un messaggio di errore per il controllo DataGridViewCell corrente. |
Formatted |
Ottiene il valore formattato del controllo DataGridViewCell corrente. |
Graphics |
Ottiene la struttura Graphics utilizzata per disegnare il controllo DataGridViewCell. |
Handled |
Ottiene o imposta un valore che indica se il gestore eventi ha gestito completamente l'evento o se il sistema deve proseguire la propria elaborazione. (Ereditato da HandledEventArgs) |
Paint |
Parti della cella da disegnare. |
Row |
Ottiene l'indice di riga del controllo DataGridViewCell corrente. |
State |
Ottiene lo stato del controllo DataGridViewCell corrente. |
Value |
Ottiene il valore del controllo DataGridViewCell corrente. |
Equals(Object) |
Determina se l'oggetto specificato è uguale all'oggetto corrente. (Ereditato da Object) |
Get |
Funge da funzione hash predefinita. (Ereditato da Object) |
Get |
Ottiene l'oggetto Type dell'istanza corrente. (Ereditato da Object) |
Memberwise |
Crea una copia superficiale dell'oggetto Object corrente. (Ereditato da Object) |
Paint(Rectangle, Data |
Disegna le parti della cella specificate per l'area compresa nei limiti specificati. |
Paint |
Disegna lo sfondo della cella per l'area compresa nei limiti specificati. |
Paint |
Disegna il contenuto della cella per l'area compresa nei limiti specificati. |
To |
Restituisce una stringa che rappresenta l'oggetto corrente. (Ereditato da Object) |
Prodotto | Versioni |
---|---|
.NET Framework | 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, 3.1, 5, 6, 7, 8, 9, 10 |
Feedback su .NET
.NET è un progetto di open source. Selezionare un collegamento per fornire feedback: