DataGridView.RowPrePaint Olay
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
bir DataGridViewRow boyanmadan önce gerçekleşir.
public:
event System::Windows::Forms::DataGridViewRowPrePaintEventHandler ^ RowPrePaint;
public event System.Windows.Forms.DataGridViewRowPrePaintEventHandler RowPrePaint;
public event System.Windows.Forms.DataGridViewRowPrePaintEventHandler? RowPrePaint;
member this.RowPrePaint : System.Windows.Forms.DataGridViewRowPrePaintEventHandler
Public Custom Event RowPrePaint As DataGridViewRowPrePaintEventHandler
Olay Türü
Örnekler
Aşağıdaki kod örneğinde, satır seçiliyse gradyan satır arka planını boyamak için olay işleyicisinin RowPrePaint nasıl kullanılacağı gösterilmektedir. Bu örnek, Nasıl yapılır: Windows Forms DataGridView Denetiminde 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.
// 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
Açıklamalar
Denetimdeki satırların görünümünü özelleştirmek için bu olayı tek başına veya olayla RowPostPaint 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 DataGridViewRowPrePaintEventArgs 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 Denetim İşleme. Visual Studio 2005 kullanıyorsanız, DataGridView denetimiyle kullanabileceğiniz büyük bir standart görüntü kitaplığına da erişebilirsiniz.
Olayları işleme hakkında daha fazla bilgi için bkz. Olayları İşleme ve Oluşturma.