DataGridViewRow.GetPreferredHeight Método
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.
Calcula a altura ideal da linha especificada com base nos critérios especificados.
public:
virtual int GetPreferredHeight(int rowIndex, System::Windows::Forms::DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth);
public virtual int GetPreferredHeight(int rowIndex, System.Windows.Forms.DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth);
abstract member GetPreferredHeight : int * System.Windows.Forms.DataGridViewAutoSizeRowMode * bool -> int
override this.GetPreferredHeight : int * System.Windows.Forms.DataGridViewAutoSizeRowMode * bool -> int
Public Overridable Function GetPreferredHeight (rowIndex As Integer, autoSizeRowMode As DataGridViewAutoSizeRowMode, fixedWidth As Boolean) As Integer
Parâmetros
- rowIndex
- Int32
O índice da linha cuja altura preferida é calculada.
- autoSizeRowMode
- DataGridViewAutoSizeRowMode
A DataGridViewAutoSizeRowMode que especifica um modo automático de dimensionamento.
- fixedWidth
- Boolean
true para calcular a altura preferida para uma largura de célula fixa; caso contrário, false.
Devoluções
A altura ideal da linha, em píxeis.
Exceções
autoSizeRowMode não é um valor válido DataGridViewAutoSizeRowMode .
O rowIndex não está no intervalo válido de 0 ao número de linhas no controlo menos 1.
Exemplos
O exemplo de código seguinte utiliza o GetPreferredHeight método para determinar o novo preenchimento para uma linha que foi redimensionada. 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.
// Adjusts the padding when the user changes the row height so that
// the normal cell content is fully displayed and any extra
// height is used for the content that spans multiple columns.
void dataGridView1_RowHeightChanged(object sender,
DataGridViewRowEventArgs e)
{
// Calculate the new height of the normal cell content.
Int32 preferredNormalContentHeight =
e.Row.GetPreferredHeight(e.Row.Index,
DataGridViewAutoSizeRowMode.AllCellsExceptHeader, true) -
e.Row.DefaultCellStyle.Padding.Bottom;
// Specify a new padding.
Padding newPadding = e.Row.DefaultCellStyle.Padding;
newPadding.Bottom = e.Row.Height - preferredNormalContentHeight;
e.Row.DefaultCellStyle.Padding = newPadding;
}
' Adjusts the padding when the user changes the row height so that
' the normal cell content is fully displayed and any extra
' height is used for the content that spans multiple columns.
Sub dataGridView1_RowHeightChanged(ByVal sender As Object, _
ByVal e As DataGridViewRowEventArgs) _
Handles dataGridView1.RowHeightChanged
' Calculate the new height of the normal cell content.
Dim preferredNormalContentHeight As Int32 = _
e.Row.GetPreferredHeight(e.Row.Index, _
DataGridViewAutoSizeRowMode.AllCellsExceptHeader, True) - _
e.Row.DefaultCellStyle.Padding.Bottom()
' Specify a new padding.
Dim newPadding As Padding = e.Row.DefaultCellStyle.Padding
newPadding.Bottom = e.Row.Height - preferredNormalContentHeight
e.Row.DefaultCellStyle.Padding = newPadding
End Sub
Observações
Esta propriedade é utilizada pela funcionalidade automática de dimensionamento baseada em conteúdo do DataGridView controlo para determinar a altura ideal de uma linha. O rowIndex valor permite-te especificar o índice real de linhas de uma linha partilhada. (As linhas partilhadas têm Index valores de propriedade de -1.)
Um valor de parâmetro calcula false a altura da linha com base nas larguras calculadas das colunas que alcançarão razões ideais altura-largura da fixedWidth célula.
Para que o conteúdo das células se enrole em múltiplas linhas, o estilo de célula em efeito para a célula deve ter um WrapMode valor de propriedade de True.
Para mais informações sobre dimensionamento automático, consulte Opções de Dimensionamento no Windows Forms Controlo DataGridView.
Aplica-se a
Ver também
- DataGridView
- DataGridViewAutoSizeRowMode
- WrapMode
- GetPreferredWidth(DataGridViewAutoSizeColumnMode, Boolean)
- Como personalizar a aparência das linhas no Controle DataGridView no Windows Forms
- Opções de dimensões no controlo DataGridView do Windows Forms
- Práticas recomendadas para escalonar o controlo DataGridView do Windows Forms