DataGridView.AutoResizeColumnHeadersHeight 方法

定义

调整列标题的高度以适应标题内容。Adjusts the height of the column headers to fit the header contents.

重载

AutoResizeColumnHeadersHeight(Int32, Boolean, Boolean)

基于指定列中标题内容的更改来调整列标题的高度,还可以选择在列和/或行标题的宽度随后进行调整的假定条件下计算高度。Adjusts the height of the column headers based on changes to the contents of the header in the specified column, optionally calculating the height with the expectation that the column and/or row header widths will subsequently be adjusted.

AutoResizeColumnHeadersHeight(Boolean, Boolean)

调整列标题的高度以适应其内容,还可以选择在列和/或行标题的宽度随后进行调整的假定条件下计算高度。Adjusts the height of the column headers to fit their contents, optionally calculating the height with the expectation that the column and/or row header widths will subsequently be adjusted.

AutoResizeColumnHeadersHeight()

调整列标题的高度以适应最大列标题的内容。Adjusts the height of the column headers to fit the contents of the largest column header.

AutoResizeColumnHeadersHeight(Int32)

基于指定列中的标题内容的更改来调整列标题的高度。Adjusts the height of the column headers based on changes to the contents of the header in the specified column.

AutoResizeColumnHeadersHeight(Int32, Boolean, Boolean)

基于指定列中标题内容的更改来调整列标题的高度,还可以选择在列和/或行标题的宽度随后进行调整的假定条件下计算高度。Adjusts the height of the column headers based on changes to the contents of the header in the specified column, optionally calculating the height with the expectation that the column and/or row header widths will subsequently be adjusted.

protected:
 void AutoResizeColumnHeadersHeight(int columnIndex, bool fixedRowHeadersWidth, bool fixedColumnWidth);
protected void AutoResizeColumnHeadersHeight (int columnIndex, bool fixedRowHeadersWidth, bool fixedColumnWidth);
member this.AutoResizeColumnHeadersHeight : int * bool * bool -> unit
Protected Sub AutoResizeColumnHeadersHeight (columnIndex As Integer, fixedRowHeadersWidth As Boolean, fixedColumnWidth As Boolean)

参数

columnIndex
Int32

其内容应当用于确定新高度的列标题的索引。The index of the column header whose contents should be used to determine new height.

fixedRowHeadersWidth
Boolean

如果要基于行标题的当前宽度来计算新高度,则为true ;如果要在行标题的宽度也进行调整的假定条件下计算高度,则为 falsetrue to calculate the new height based on the current width of the row headers; false to calculate the height with the expectation that the row headers width will also be adjusted.

fixedColumnWidth
Boolean

如果要基于指定列的当前宽度计算新高度,则为 true;如果要在列宽也进行调整的假定条件下计算高度,则为 falsetrue to calculate the new height based on the current width of the specified column; false to calculate the height with the expectation that the column width will also be adjusted.

异常

columnIndex 不在 0 到列数减 1 的有效范围内。columnIndex is not in the valid range of 0 to the number of columns minus 1.

注解

如果您想要控制列标题调整的时间,如果用户编辑或更改了绑定数据源,则只更改指定列中标题的内容。This method is useful if you want to control when the column headers resize if only the contents of the header in the specified column have changed as a result of user edits or changes to a bound data source. 如果内容更改需要列标题的高度,则仅对每个方法调用进行一次调整;如果以后列标题的内容发生更改,则列标题不会自动调整。The height of the column headers is adjusted only once per method call if the content change requires it; if the contents of the column headers later change, the column headers will not automatically adjust. 若要将列标题设置为在其内容更改时自动调整大小,请使用 ColumnHeadersHeightSizeMode 属性。To set the column headers to automatically resize when their contents change, use the ColumnHeadersHeightSizeMode property.

当调整列标题的大小时,若要将单元格内容换行,则单元格的有效单元格样式必须将 WrapMode 属性值设置 @no__t。For cell contents to wrap onto multiple lines when the column headers are resized, the cell style in effect for the cell must have a WrapMode property value of True.

此重载受到保护,旨在使你能够在派生 @no__t 0 类中实现理想的单元格高度与宽度的比率。This overload is protected and is designed to enable you to achieve ideal cell height-to-width ratios in a derived DataGridView class. 如果 @no__t 0 或 @no__t 1 参数 false,则将计算列标题的高度,并将调用方法,如 AutoResizeColumns 和 @no__t,接下来。If the fixedColumnWidth or fixedRowHeadersWidth parameters are false, the height of the column headers will be calculated with the expectation that you will call the methods such as AutoResizeColumns and AutoResizeRowHeadersWidth next.

有关以编程方式调整大小的详细信息,请参阅Windows 窗体 DataGridView 控件中的调整大小选项For more information about programmatic resizing, see Sizing Options in the Windows Forms DataGridView Control.

另请参阅

AutoResizeColumnHeadersHeight(Boolean, Boolean)

调整列标题的高度以适应其内容,还可以选择在列和/或行标题的宽度随后进行调整的假定条件下计算高度。Adjusts the height of the column headers to fit their contents, optionally calculating the height with the expectation that the column and/or row header widths will subsequently be adjusted.

protected:
 void AutoResizeColumnHeadersHeight(bool fixedRowHeadersWidth, bool fixedColumnsWidth);
protected void AutoResizeColumnHeadersHeight (bool fixedRowHeadersWidth, bool fixedColumnsWidth);
member this.AutoResizeColumnHeadersHeight : bool * bool -> unit
Protected Sub AutoResizeColumnHeadersHeight (fixedRowHeadersWidth As Boolean, fixedColumnsWidth As Boolean)

参数

fixedRowHeadersWidth
Boolean

如果要基于行标题的当前宽度来计算新高度,则为 true;如果要在行标题的宽度也进行调整的假定条件下计算高度,则为 falsetrue to calculate the new height based on the current width of the row headers; false to calculate the height with the expectation that the row headers width will also be adjusted.

fixedColumnsWidth
Boolean

如果基于当前的列宽计算新高度,则为 true;如果在列宽也进行调整的假定条件下计算高度,则为 falsetrue to calculate the new height based on the current column widths; false to calculate the height with the expectation that the column widths will also be adjusted.

注解

如果要控制列标题调整的时间,此方法非常有用。This method is useful if you want to control when the column headers resize. 列标题的高度仅在每个方法调用中进行了一次调整;如果以后列标题的内容发生更改,则列标题不会自动调整。The height of the column headers is adjusted only once per method call; if the contents of the column headers later change, the column headers will not automatically adjust. 若要将列标题设置为在其内容更改时自动调整大小,请使用 ColumnHeadersHeightSizeMode 属性。To set the column headers to automatically resize when their contents change, use the ColumnHeadersHeightSizeMode property.

当调整列标题的大小时,若要将单元格内容换行,则单元格的有效单元格样式必须将 WrapMode 属性值设置 @no__t。For cell contents to wrap onto multiple lines when the column headers are resized, the cell style in effect for the cell must have a WrapMode property value of True.

此重载受到保护,旨在使你能够在派生 @no__t 0 类中实现理想的单元格高度与宽度的比率。This overload is protected and is designed to enable you to achieve ideal cell height-to-width ratios in a derived DataGridView class. 如果 @no__t 0 或 @no__t 1 参数 false,则将计算列标题的高度,并将调用方法,如 AutoResizeColumns 和 @no__t,接下来。If the fixedColumnsWidth or fixedRowHeadersWidth parameters are false, the height of the column headers will be calculated with the expectation that you will call the methods such as AutoResizeColumns and AutoResizeRowHeadersWidth next.

有关以编程方式调整大小的详细信息,请参阅Windows 窗体 DataGridView 控件中的调整大小选项For more information about programmatic resizing, see Sizing Options in the Windows Forms DataGridView Control.

另请参阅

AutoResizeColumnHeadersHeight()

调整列标题的高度以适应最大列标题的内容。Adjusts the height of the column headers to fit the contents of the largest column header.

public:
 void AutoResizeColumnHeadersHeight();
public void AutoResizeColumnHeadersHeight ();
member this.AutoResizeColumnHeadersHeight : unit -> unit
Public Sub AutoResizeColumnHeadersHeight ()

示例

下面的代码示例演示如何在按钮单击时调整列标题和行的大小。The following code example demonstrates how to resize column headers and rows as a result of a button click.

void Button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
   // Resize the height of the column headers. 
   dataGridView1->AutoResizeColumnHeadersHeight();

   // Resize all the row heights to fit the contents of all non-header cells.
   dataGridView1->AutoResizeRows(
         DataGridViewAutoSizeRowsMode::AllCellsExceptHeaders);
}
private void button1_Click(object sender, System.EventArgs e)
{
    // Resize the height of the column headers. 
    dataGridView1.AutoResizeColumnHeadersHeight();

    // Resize all the row heights to fit the contents of all non-header cells.
    dataGridView1.AutoResizeRows(
        DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders);
}
Private Sub button1_Click(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles button1.Click

    ' Resize the height of the column headers. 
    dataGridView1.AutoResizeColumnHeadersHeight()

    ' Resize all the row heights to fit the contents of all 
    ' non-header cells.
    dataGridView1.AutoResizeRows( _
        DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders)

End Sub

注解

如果要控制列标题调整的时间,此方法非常有用。This method is useful if you want to control when the column headers resize. 列标题的高度仅在每个方法调用中进行了一次调整;如果以后列标题的内容发生更改,则列标题不会自动调整。The height of the column headers is adjusted only once per method call; if the contents of the column headers later change, the column headers will not automatically adjust. 若要将列标题设置为在其内容更改时自动调整大小,请使用 ColumnHeadersHeightSizeMode 属性。To set the column headers to automatically resize when their contents change, use the ColumnHeadersHeightSizeMode property.

当调整列标题的大小时,若要将单元格内容换行,则单元格的有效单元格样式必须将 WrapMode 属性值设置 @no__t。For cell contents to wrap onto multiple lines when the column headers are resized, the cell style in effect for the cell must have a WrapMode property value of True.

有关以编程方式调整大小的详细信息,请参阅Windows 窗体 DataGridView 控件中的调整大小选项For more information about programmatic resizing, see Sizing Options in the Windows Forms DataGridView Control.

另请参阅

AutoResizeColumnHeadersHeight(Int32)

基于指定列中的标题内容的更改来调整列标题的高度。Adjusts the height of the column headers based on changes to the contents of the header in the specified column.

public:
 void AutoResizeColumnHeadersHeight(int columnIndex);
public void AutoResizeColumnHeadersHeight (int columnIndex);
member this.AutoResizeColumnHeadersHeight : int -> unit
Public Sub AutoResizeColumnHeadersHeight (columnIndex As Integer)

参数

columnIndex
Int32

某一列的索引,该列包含内容已更改的标题。The index of the column containing the header with the changed content.

异常

columnIndex 不在 0 到列数减 1 的有效范围内。columnIndex is not in the valid range of 0 to the number of columns minus 1.

注解

如果您想要控制列标题调整的时间,如果用户编辑或更改了绑定数据源,则只更改指定列中标题的内容。This method is useful if you want to control when the column headers resize if only the contents of the header in the specified column have changed as a result of user edits or changes to a bound data source. 如果内容更改需要列标题的高度,则仅对每个方法调用进行一次调整;如果以后列标题的内容发生更改,则列标题不会自动调整。The height of the column headers is adjusted only once per method call if the content change requires it; if the contents of the column headers later change, the column headers will not automatically adjust. 若要将列标题设置为在其内容更改时自动调整大小,请使用 ColumnHeadersHeightSizeMode 属性。To set the column headers to automatically resize when their contents change, use the ColumnHeadersHeightSizeMode property.

当调整列标题的大小时,若要将单元格内容换行,则单元格的有效单元格样式必须将 WrapMode 属性值设置 @no__t。For cell contents to wrap onto multiple lines when the column headers are resized, the cell style in effect for the cell must have a WrapMode property value of True.

有关以编程方式调整大小的详细信息,请参阅Windows 窗体 DataGridView 控件中的调整大小选项For more information about programmatic resizing, see Sizing Options in the Windows Forms DataGridView Control.

另请参阅

适用于