DataGridViewRowPrePaintEventArgs Classe
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Fornece dados para o RowPrePaint evento.
public ref class DataGridViewRowPrePaintEventArgs : System::ComponentModel::HandledEventArgs
public class DataGridViewRowPrePaintEventArgs : System.ComponentModel.HandledEventArgs
type DataGridViewRowPrePaintEventArgs = class
inherit HandledEventArgs
Public Class DataGridViewRowPrePaintEventArgs
Inherits HandledEventArgs
- Herança
Exemplos
O exemplo de código seguinte demonstra como lidar com o RowPrePaint evento para desenhar um fundo personalizado para células selecionadas. Este exemplo de código faz parte de um exemplo maior fornecido em Como Personalizar: A Aparência das Linhas no Controlo Windows Forms DataGridView.
// 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
Observações
O RowPrePaint evento ocorre antes de uma linha ser pintada num DataGridView controlo. RowPrePaint Permite ajustar manualmente a aparência da linha antes de qualquer célula da linha ser pintada. Isto é útil se quiser personalizar a linha, por exemplo, para produzir uma linha onde o conteúdo de uma coluna abrange várias colunas. Use as propriedades em DataGridViewRowPrePaintEventArgs para obter as definições da linha sem aceder diretamente à linha na DataGridViewlinha .
Construtores
| Name | Description |
|---|---|
| DataGridViewRowPrePaintEventArgs(DataGridView, Graphics, Rectangle, Rectangle, Int32, DataGridViewElementStates, String, DataGridViewCellStyle, Boolean, Boolean) |
Inicializa uma nova instância da DataGridViewRowPrePaintEventArgs classe. |
Propriedades
| Name | Description |
|---|---|
| ClipBounds |
Obtém ou ajusta a área DataGridView que precisa de ser repintada. |
| ErrorText |
Obtém uma cadeia que representa uma mensagem de erro para a corrente DataGridViewRow. |
| Graphics |
Obtém o Graphics usado para pintar a corrente DataGridViewRow. |
| Handled |
Recebe ou define um valor que indica se o gestor de eventos tratou completamente o evento ou se o sistema deve continuar o seu próprio processamento. (Herdado de HandledEventArgs) |
| InheritedRowStyle |
Aplica-se o estilo de célula à linha. |
| IsFirstDisplayedRow |
Obtém um valor que indica se a linha atual é a primeira linha atualmente exibida no DataGridViewarquivo . |
| IsLastVisibleRow |
Obtém um valor que indica se a linha atual é a última linha visível no DataGridView. |
| PaintParts |
As partes da célula que vão ser pintadas. |
| RowBounds |
Obtém os limites da corrente DataGridViewRow. |
| RowIndex |
Obtém o índice da corrente DataGridViewRow. |
| State |
Obtém o estado da corrente DataGridViewRow. |
Métodos
| Name | Description |
|---|---|
| DrawFocus(Rectangle, Boolean) |
Desenha o retângulo de foco em torno dos limites especificados. |
| Equals(Object) |
Determina se o objeto especificado é igual ao objeto atual. (Herdado de Object) |
| GetHashCode() |
Serve como função de hash predefinida. (Herdado de Object) |
| GetType() |
Obtém o Type da instância atual. (Herdado de Object) |
| MemberwiseClone() |
Cria uma cópia superficial do atual Object. (Herdado de Object) |
| PaintCells(Rectangle, DataGridViewPaintParts) |
Pinta as partes da célula especificadas para a área dentro dos limites especificados. |
| PaintCellsBackground(Rectangle, Boolean) |
Pinta os fundos das células para a área dentro dos limites especificados. |
| PaintCellsContent(Rectangle) |
Pinta o conteúdo da célula para a área dentro dos limites especificados. |
| PaintHeader(Boolean) |
Pinta todo o cabeçalho de linha da corrente DataGridViewRow. |
| PaintHeader(DataGridViewPaintParts) |
Pinta as partes especificadas do cabeçalho da linha atual. |
| ToString() |
Devolve uma cadeia que representa o objeto atual. (Herdado de Object) |