DataGridViewCellPaintingEventArgs Class
Provides data for the CellPainting event.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
System.EventArgs
System.ComponentModel.HandledEventArgs
System.Windows.Forms.DataGridViewCellPaintingEventArgs
| Name | Description | |
|---|---|---|
![]() | DataGridViewCellPaintingEventArgs(DataGridView, Graphics, Rectangle, Rectangle, Int32, Int32, DataGridViewElementStates, Object, Object, String, DataGridViewCellStyle, DataGridViewAdvancedBorderStyle, DataGridViewPaintParts) | Initializes a new instance of the DataGridViewCellPaintingEventArgs class. |
| Name | Description | |
|---|---|---|
![]() | AdvancedBorderStyle | Gets the border style of the current DataGridViewCell. |
![]() | CellBounds | Get the bounds of the current DataGridViewCell. |
![]() | CellStyle | Gets the cell style of the current DataGridViewCell. |
![]() | ClipBounds | Gets the area of the DataGridView that needs to be repainted. |
![]() | ColumnIndex | Gets the column index of the current DataGridViewCell. |
![]() | ErrorText | Gets a string that represents an error message for the current DataGridViewCell. |
![]() | FormattedValue | Gets the formatted value of the current DataGridViewCell. |
![]() | Graphics | Gets the Graphics used to paint the current DataGridViewCell. |
![]() | Handled | Gets or sets a value that indicates whether the event handler has completely handled the event or whether the system should continue its own processing.(Inherited from HandledEventArgs.) |
![]() | PaintParts | The cell parts that are to be painted. |
![]() | RowIndex | Gets the row index of the current DataGridViewCell. |
![]() | State | Gets the state of the current DataGridViewCell. |
![]() | Value | Gets the value of the current DataGridViewCell. |
| Name | Description | |
|---|---|---|
![]() | Equals(Object) | Determines whether the specified object is equal to the current object.(Inherited from Object.) |
![]() | Finalize() | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.) |
![]() | GetHashCode() | Serves as the default hash function. (Inherited from Object.) |
![]() | GetType() | |
![]() | MemberwiseClone() | |
![]() | Paint(Rectangle, DataGridViewPaintParts) | Paints the specified parts of the cell for the area in the specified bounds. |
![]() | PaintBackground(Rectangle, Boolean) | Paints the cell background for the area in the specified bounds. |
![]() | PaintContent(Rectangle) | Paints the cell content for the area in the specified bounds. |
![]() | ToString() | Returns a string that represents the current object.(Inherited from Object.) |
The CellPainting event is raised for each DataGridViewCell that is visible on a DataGridView. To improve performance, set the properties in a DataGridViewCellPaintingEventArgs to change the appearance of the cell instead of directly accessing a cell in the DataGridView. If you manually paint the cell, set the HandledEventArgs.Handled property to true. If you do not set HandledEventArgs.Handled to true, the cell will paint over your customizations.
The following code example illustrates the use of this type. For more information, see How to: Customize the Appearance of Cells in the Windows Forms DataGridView Control.
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
Available since 2.0
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


