DataGridViewRowPostPaintEventArgs 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 RowPostPaint evento.
public ref class DataGridViewRowPostPaintEventArgs : EventArgs
public class DataGridViewRowPostPaintEventArgs : EventArgs
type DataGridViewRowPostPaintEventArgs = class
inherit EventArgs
Public Class DataGridViewRowPostPaintEventArgs
Inherits EventArgs
- Herança
Exemplos
O exemplo de código seguinte demonstra como lidar com o RowPostPaint evento para que o conteúdo de uma célula abrange toda a linha. 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 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
Observações
O RowPostPaint evento ocorre depois de uma linha ser pintada num DataGridView controlo. RowPostPaint permite ajustar manualmente o aspeto da linha depois de as células da linha serem pintadas. Isto é útil se quiseres personalizar a linha.
Construtores
| Name | Description |
|---|---|
| DataGridViewRowPostPaintEventArgs(DataGridView, Graphics, Rectangle, Rectangle, Int32, DataGridViewElementStates, String, DataGridViewCellStyle, Boolean, Boolean) |
Inicializa uma nova instância da DataGridViewRowPostPaintEventArgs 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. |
| InheritedRowStyle |
Aplica o estilo de célula à corrente DataGridViewRow. |
| IsFirstDisplayedRow |
Obtém um valor que indica se a linha atual é a primeira linha exibida no DataGridView. |
| IsLastVisibleRow |
Obtém um valor que indica se a linha atual é a última linha visível exibida no DataGridView. |
| 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) |