DataGridViewPaintParts Enum
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Definierar värden för att ange de delar av en DataGridViewCell som ska målas.
Den här uppräkningen stöder en bitvis kombination av dess medlemsvärden.
public enum class DataGridViewPaintParts
[System.Flags]
public enum DataGridViewPaintParts
[<System.Flags>]
type DataGridViewPaintParts =
Public Enum DataGridViewPaintParts
- Arv
- Attribut
Fält
| Name | Värde | Description |
|---|---|---|
| None | 0 | Inget ska målas. |
| Background | 1 | Cellens bakgrund ska målas. |
| Border | 2 | Cellens kantlinje ska målas. |
| ContentBackground | 4 | Cellinnehållets bakgrund ska målas. |
| ContentForeground | 8 | Förgrunden för cellinnehållet ska målas. |
| ErrorIcon | 16 | Cellfelikonen ska målas. |
| Focus | 32 | Fokusrektangeln ska målas runt cellen. |
| SelectionBackground | 64 | Cellens bakgrund ska målas när cellen är markerad. |
| All | 127 | Alla delar av cellen ska målas. |
Exempel
Följande kodexempel illustrerar användningen av den här typen. Det här exemplet är en del av ett större exempel i Så här: Anpassa utseendet på rader i Windows Forms DataGridView Control.
// Paints the custom selection background for selected rows.
void dataGridView1_RowPrePaint(object sender,
DataGridViewRowPrePaintEventArgs e)
{
// Do not automatically paint the focus rectangle.
e.PaintParts &= ~DataGridViewPaintParts.Focus;
// Determine whether the cell should be painted
// with the custom selection background.
if ((e.State & DataGridViewElementStates.Selected) ==
DataGridViewElementStates.Selected)
{
// Calculate the bounds of the row.
Rectangle rowBounds = new Rectangle(
this.dataGridView1.RowHeadersWidth, e.RowBounds.Top,
this.dataGridView1.Columns.GetColumnsWidth(
DataGridViewElementStates.Visible) -
this.dataGridView1.HorizontalScrollingOffset + 1,
e.RowBounds.Height);
// Paint the custom selection background.
using (Brush backbrush =
new System.Drawing.Drawing2D.LinearGradientBrush(rowBounds,
this.dataGridView1.DefaultCellStyle.SelectionBackColor,
e.InheritedRowStyle.ForeColor,
System.Drawing.Drawing2D.LinearGradientMode.Horizontal))
{
e.Graphics.FillRectangle(backbrush, rowBounds);
}
}
}
' Paints the custom selection background for selected rows.
Sub dataGridView1_RowPrePaint(ByVal sender As Object, _
ByVal e As DataGridViewRowPrePaintEventArgs) _
Handles dataGridView1.RowPrePaint
' Do not automatically paint the focus rectangle.
e.PaintParts = e.PaintParts And Not DataGridViewPaintParts.Focus
' Determine whether the cell should be painted with the
' custom selection background.
If (e.State And DataGridViewElementStates.Selected) = _
DataGridViewElementStates.Selected Then
' Calculate the bounds of the row.
Dim rowBounds As New Rectangle( _
Me.dataGridView1.RowHeadersWidth, e.RowBounds.Top, _
Me.dataGridView1.Columns.GetColumnsWidth( _
DataGridViewElementStates.Visible) - _
Me.dataGridView1.HorizontalScrollingOffset + 1, _
e.RowBounds.Height)
' Paint the custom selection background.
Dim backbrush As New _
System.Drawing.Drawing2D.LinearGradientBrush(rowBounds, _
Me.dataGridView1.DefaultCellStyle.SelectionBackColor, _
e.InheritedRowStyle.ForeColor, _
System.Drawing.Drawing2D.LinearGradientMode.Horizontal)
Try
e.Graphics.FillRectangle(backbrush, rowBounds)
Finally
backbrush.Dispose()
End Try
End If
End Sub
Kommentarer
Den här uppräkningen används av den skyddade DataGridViewCell.Paint metoden och av hanterare för CellPaintingkontrollens , RowPrePaintoch RowPostPaint händelser DataGridView .