DataGridViewRowPostPaintEventArgs Klas

Definitie

Biedt gegevens voor de RowPostPaint gebeurtenis.

public ref class DataGridViewRowPostPaintEventArgs : EventArgs
public class DataGridViewRowPostPaintEventArgs : EventArgs
type DataGridViewRowPostPaintEventArgs = class
    inherit EventArgs
Public Class DataGridViewRowPostPaintEventArgs
Inherits EventArgs
Overname
DataGridViewRowPostPaintEventArgs

Voorbeelden

In het volgende codevoorbeeld ziet u hoe u de RowPostPaint gebeurtenis kunt afhandelen om de inhoud van een cel over de hele rij te maken. Dit codevoorbeeld maakt deel uit van een groter voorbeeld in How to: Het uiterlijk van rijen aanpassen in het Windows Forms DataGridView-besturingselement.

// Paints the content that spans multiple columns and the focus rectangle.
void dataGridView1_RowPostPaint(object sender,
    DataGridViewRowPostPaintEventArgs e)
{
    // 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);

    SolidBrush forebrush = null;
    try
    {
        // Determine the foreground color.
        if ((e.State & DataGridViewElementStates.Selected) ==
            DataGridViewElementStates.Selected)
        {
            forebrush = new SolidBrush(e.InheritedRowStyle.SelectionForeColor);
        }
        else
        {
            forebrush = new SolidBrush(e.InheritedRowStyle.ForeColor);
        }

        // Get the content that spans multiple columns.
        object recipe =
            this.dataGridView1.Rows.SharedRow(e.RowIndex).Cells[2].Value;

        if (recipe != null)
        {
            String text = recipe.ToString();

            // Calculate the bounds for the content that spans multiple 
            // columns, adjusting for the horizontal scrolling position 
            // and the current row height, and displaying only whole
            // lines of text.
            Rectangle textArea = rowBounds;
            textArea.X -= this.dataGridView1.HorizontalScrollingOffset;
            textArea.Width += this.dataGridView1.HorizontalScrollingOffset;
            textArea.Y += rowBounds.Height - e.InheritedRowStyle.Padding.Bottom;
            textArea.Height -= rowBounds.Height -
                e.InheritedRowStyle.Padding.Bottom;
            textArea.Height = (textArea.Height / e.InheritedRowStyle.Font.Height) *
                e.InheritedRowStyle.Font.Height;

            // Calculate the portion of the text area that needs painting.
            RectangleF clip = textArea;
            clip.Width -= this.dataGridView1.RowHeadersWidth + 1 - clip.X;
            clip.X = this.dataGridView1.RowHeadersWidth + 1;
            RectangleF oldClip = e.Graphics.ClipBounds;
            e.Graphics.SetClip(clip);

            // Draw the content that spans multiple columns.
            e.Graphics.DrawString(
                text, e.InheritedRowStyle.Font, forebrush, textArea);

            e.Graphics.SetClip(oldClip);
        }
    }
    finally
    {
        forebrush.Dispose();
    }

    if (this.dataGridView1.CurrentCellAddress.Y == e.RowIndex)
    {
        // Paint the focus rectangle.
        e.DrawFocus(rowBounds, true);
    }
}
' Paints the content that spans multiple columns and the focus rectangle.
Sub dataGridView1_RowPostPaint(ByVal sender As Object, _
    ByVal e As DataGridViewRowPostPaintEventArgs) _
    Handles dataGridView1.RowPostPaint

    ' 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)

    Dim forebrush As SolidBrush = Nothing
    Try
        ' Determine the foreground color.
        If (e.State And DataGridViewElementStates.Selected) = _
            DataGridViewElementStates.Selected Then

            forebrush = New SolidBrush(e.InheritedRowStyle.SelectionForeColor)
        Else
            forebrush = New SolidBrush(e.InheritedRowStyle.ForeColor)
        End If

        ' Get the content that spans multiple columns.
        Dim recipe As Object = _
            Me.dataGridView1.Rows.SharedRow(e.RowIndex).Cells(2).Value

        If (recipe IsNot Nothing) Then
            Dim text As String = recipe.ToString()

            ' Calculate the bounds for the content that spans multiple 
            ' columns, adjusting for the horizontal scrolling position 
            ' and the current row height, and displaying only whole
            ' lines of text.
            Dim textArea As Rectangle = rowBounds
            textArea.X -= Me.dataGridView1.HorizontalScrollingOffset
            textArea.Width += Me.dataGridView1.HorizontalScrollingOffset
            textArea.Y += rowBounds.Height - e.InheritedRowStyle.Padding.Bottom
            textArea.Height -= rowBounds.Height - e.InheritedRowStyle.Padding.Bottom
            textArea.Height = (textArea.Height \ e.InheritedRowStyle.Font.Height) * _
                e.InheritedRowStyle.Font.Height

            ' Calculate the portion of the text area that needs painting.
            Dim clip As RectangleF = textArea
            clip.Width -= Me.dataGridView1.RowHeadersWidth + 1 - clip.X
            clip.X = Me.dataGridView1.RowHeadersWidth + 1
            Dim oldClip As RectangleF = e.Graphics.ClipBounds
            e.Graphics.SetClip(clip)

            ' Draw the content that spans multiple columns.
            e.Graphics.DrawString(text, e.InheritedRowStyle.Font, forebrush, _
                textArea)

            e.Graphics.SetClip(oldClip)
        End If
    Finally
        forebrush.Dispose()
    End Try

    If Me.dataGridView1.CurrentCellAddress.Y = e.RowIndex Then
        ' Paint the focus rectangle.
        e.DrawFocus(rowBounds, True)
    End If

End Sub

Opmerkingen

De RowPostPaint gebeurtenis treedt op nadat een rij op een DataGridView besturingselement is geschilderd. RowPostPaint hiermee kunt u het uiterlijk van de rij handmatig aanpassen nadat de cellen in de rij zijn geschilderd. Dit is handig als u de rij wilt aanpassen.

Constructors

Name Description
DataGridViewRowPostPaintEventArgs(DataGridView, Graphics, Rectangle, Rectangle, Int32, DataGridViewElementStates, String, DataGridViewCellStyle, Boolean, Boolean)

Initialiseert een nieuw exemplaar van de DataGridViewRowPostPaintEventArgs klasse.

Eigenschappen

Name Description
ClipBounds

Hiermee haalt of stelt u het gebied in van het DataGridView gebied dat opnieuw moet worden geschilderd.

ErrorText

Hiermee haalt u een tekenreeks op die een foutbericht voor de huidige DataGridViewRowvertegenwoordigt.

Graphics

Hiermee wordt de Graphics opgegeven om de huidige DataGridViewRowte schilderen.

InheritedRowStyle

Hiermee wordt de celstijl toegepast op de huidige DataGridViewRow.

IsFirstDisplayedRow

Hiermee wordt een waarde opgehaald die aangeeft of de huidige rij de eerste rij is die wordt weergegeven in de DataGridView.

IsLastVisibleRow

Hiermee wordt een waarde opgehaald die aangeeft of de huidige rij de laatste zichtbare rij is die wordt weergegeven in de DataGridView.

RowBounds

Haal de grenzen van de huidige DataGridViewRow.

RowIndex

Hiermee haalt u de index van de huidige DataGridViewRowop.

State

Hiermee haalt u de status van de huidige DataGridViewRowop.

Methoden

Name Description
DrawFocus(Rectangle, Boolean)

Hiermee tekent u de focusrechthoek rond de opgegeven grenzen.

Equals(Object)

Bepaalt of het opgegeven object gelijk is aan het huidige object.

(Overgenomen van Object)
GetHashCode()

Fungeert als de standaardhashfunctie.

(Overgenomen van Object)
GetType()

Hiermee haalt u de Type huidige instantie op.

(Overgenomen van Object)
MemberwiseClone()

Hiermee maakt u een ondiepe kopie van de huidige Object.

(Overgenomen van Object)
PaintCells(Rectangle, DataGridViewPaintParts)

Hiermee worden de opgegeven celonderdelen voor het gebied in de opgegeven grenzen geschilderd.

PaintCellsBackground(Rectangle, Boolean)

Hiermee worden de celachtergronden voor het gebied in de opgegeven grenzen weergegeven.

PaintCellsContent(Rectangle)

Hiermee wordt de celinhoud voor het gebied in de opgegeven grenzen weergegeven.

PaintHeader(Boolean)

Hiermee wordt de volledige rijkop van de huidige DataGridViewRowweergegeven.

PaintHeader(DataGridViewPaintParts)

Hiermee worden de opgegeven onderdelen van de rijkop van de huidige rij weergegeven.

ToString()

Retourneert een tekenreeks die het huidige object vertegenwoordigt.

(Overgenomen van Object)

Van toepassing op

Zie ook