DataGridView.RowPostPaint Olay

Tanım

Bir DataGridViewRow boyandıktan sonra gerçekleşir.

C#
public event System.Windows.Forms.DataGridViewRowPostPaintEventHandler RowPostPaint;
C#
public event System.Windows.Forms.DataGridViewRowPostPaintEventHandler? RowPostPaint;

Olay Türü

Örnekler

Aşağıdaki kod örneği, normal hücre değerlerinin altındaki satırın tamamını kapsayan RowPostPaint metin içeriğini boyamak için olay işleyicisinin nasıl kullanılacağını gösterir. Bu örnek, How to: Customize the Appearance of Rows in the Windows Forms DataGridView Control (DataGridView Denetimindeki Satırların Görünümünü Özelleştirme) bölümünde bulunan daha büyük bir örneğin bir parçasıdır.

C#
// 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);
    }
}

Açıklamalar

Denetimdeki satırların görünümünü özelleştirmek için bu olayı tek başına veya olayla RowPrePaint birlikte işleyebilirsiniz. Satırların tamamını kendiniz boyayabilirsiniz veya satırların belirli bölümlerini boyayabilirsiniz ve diğer bölümleri boyamak için sınıfın DataGridViewRowPostPaintEventArgs aşağıdaki yöntemlerini kullanabilirsiniz:

Geçerli temayı kullanarak standart denetimleri boyamak için sınıfını da kullanabilirsiniz VisualStyleRenderer . Daha fazla bilgi için bkz . Görsel Stiller ile İşleme Denetimleri. Visual Studio 2005 kullanıyorsanız, denetimle birlikte kullanabileceğiniz büyük bir standart görüntü kitaplığına DataGridView da erişebilirsiniz.

Olayları işleme hakkında daha fazla bilgi için bkz. Olayları İşleme ve Oluşturma.

Şunlara uygulanır

Ürün Sürümler
.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

Ayrıca bkz.