DataGridViewRowPrePaintEventArgs 類別
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供 RowPrePaint 事件的資料。
public ref class DataGridViewRowPrePaintEventArgs : System::ComponentModel::HandledEventArgs
public class DataGridViewRowPrePaintEventArgs : System.ComponentModel.HandledEventArgs
type DataGridViewRowPrePaintEventArgs = class
inherit HandledEventArgs
Public Class DataGridViewRowPrePaintEventArgs
Inherits HandledEventArgs
- 繼承
下列程式碼範例示範如何處理 RowPrePaint 事件,以繪製所選儲存格的自訂背景。 此程式碼範例是How to: Customize the Appearance of Rows in the 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
此 RowPrePaint 事件會在在控制項上 DataGridView 繪製資料列之前發生。 RowPrePaint 可讓您在繪製資料列中的任何儲存格之前,手動調整資料列的外觀。 如果您想要自訂資料列,例如產生一個資料行內容跨越多個資料行的資料列,這會很有用。 使用 中的 DataGridViewRowPrePaintEventArgs 屬性來取得資料列的設定,而不需要直接存取 中的資料 DataGridView 列。
Clip |
取得或設定需要重新繪製的 DataGridView 區域。 |
Error |
取得字串,表示目前 DataGridViewRow 的錯誤訊息。 |
Graphics |
取得用來繪製目前 Graphics 的 DataGridViewRow。 |
Handled |
取得或設定值,指出事件處理常式已經完全處理事件或系統應繼續自己的處理。 (繼承來源 HandledEventArgs) |
Inherited |
取得套用至資料列的儲存格樣式。 |
Is |
取得值,指出目前的資料列是否為 DataGridView 中所顯示的第一個資料列。 |
Is |
取得值,指出目前的資料列是否為 DataGridView 中最後一個可見資料列。 |
Paint |
要繪製的儲存格部分。 |
Row |
取得目前 DataGridViewRow 的界限。 |
Row |
取得目前 DataGridViewRow 的索引。 |
State |
取得目前 DataGridViewRow 的狀態。 |
Draw |
在指定的界限四周繪製焦點矩形。 |
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
Get |
做為預設雜湊函式。 (繼承來源 Object) |
Get |
取得目前執行個體的 Type。 (繼承來源 Object) |
Memberwise |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
Paint |
繪製所指定界限內區域之指定的儲存格部分。 |
Paint |
繪製所指定界限內區域的儲存格背景。 |
Paint |
繪製所指定界限內區域的儲存格內容。 |
Paint |
繪製目前 DataGridViewRow 的整個資料列行首。 |
Paint |
繪製目前資料列之資料列行首所指定的部分。 |
To |
傳回代表目前物件的字串。 (繼承來源 Object) |
產品 | 版本 |
---|---|
.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 |