Console.BufferHeight 属性

定义

获取或设置缓冲区的高度。Gets or sets the height of the buffer area.

public:
 static property int BufferHeight { int get(); void set(int value); };
public static int BufferHeight { get; set; }
member this.BufferHeight : int with get, set
Public Shared Property BufferHeight As Integer

属性值

缓冲区的当前高度,以行为单位。The current height, in rows, of the buffer area.

例外

Set 操作中的值小于或等于零。The value in a set operation is less than or equal to zero.

- 或 --or- 集运算中的值大于或等于 MaxValueThe value in a set operation is greater than or equal to MaxValue.

- 或 --or- Set 操作中的值小于 WindowTop + WindowHeightThe value in a set operation is less than WindowTop + WindowHeight.

用户没有执行此操作的权限。The user does not have permission to perform this action.

出现 I/O 错误。An I/O error occurred.

设置操作在 Windows 之外的操作系统上调用。The set operation is invoked on an operating system other than Windows.

示例

此示例演示 BufferHeightBufferWidth 属性。This example demonstrates the BufferHeight and BufferWidth properties. 该示例将报告操作系统窗口的尺寸,其缓冲区大小为300行,85列。The example reports the dimensions of an operating system window set to a buffer size of 300 rows and 85 columns.

// This example demonstrates the Console.BufferHeight and 
//                               Console.BufferWidth properties.
using namespace System;
int main()
{
   Console::WriteLine( "The current buffer height is {0} rows.", Console::BufferHeight );
   Console::WriteLine( "The current buffer width is {0} columns.", Console::BufferWidth );
}

/*
This example produces the following results:

The current buffer height is 300 rows.
The current buffer width is 85 columns.
*/
// This example demonstrates the Console.BufferHeight and 
//                               Console.BufferWidth properties.
using System;

class Sample 
{
    public static void Main() 
    {
    Console.WriteLine("The current buffer height is {0} rows.",
                      Console.BufferHeight);
    Console.WriteLine("The current buffer width is {0} columns.",
                      Console.BufferWidth);
    }
}
/*
This example produces the following results:

The current buffer height is 300 rows.
The current buffer width is 85 columns.
*/
' This example demonstrates the Console.BufferHeight and 
'                               Console.BufferWidth properties.
Class Sample
   Public Shared Sub Main()
      Console.WriteLine("The current buffer height is {0} rows.", _
                        Console.BufferHeight)
      Console.WriteLine("The current buffer width is {0} columns.", _
                        Console.BufferWidth)
   End Sub
End Class
'
'This example produces the following results:
'
'The current buffer height is 300 rows.
'The current buffer width is 85 columns.
'

注解

此属性定义由控制台模式窗口访问的缓冲区中存储的行数(或行数)。This property defines the number of rows (or lines) stored in the buffer that is accessed by a console mode window. 与此相反,WindowHeight 属性定义在任何特定时间实际显示在控制台窗口中的行数。In contrast, the WindowHeight property defines the number of rows that are actually displayed in the console window at any particular time. 如果实际上写入缓冲区的行数超过了 WindowHeight 属性定义的行数,则窗口可以垂直滚动,以便显示与 WindowHeight 属性相同的行数,并将其放到缓冲区中的任意位置。If the number of rows actually written to the buffer exceeds the number of rows defined by the WindowHeight property, the window can be scrolled vertically so that it displays a contiguous number of rows that are equal to the WindowHeight property and are located anywhere in the buffer.

如果 set 操作减小 BufferHeight 属性的值,则会删除最上方的行。If a set operation decreases the value of the BufferHeight property, the uppermost lines are removed. 例如,如果行数从300减少到250,则将删除第0行到第49行,现有行50到299将变为第0到249行。For example, if the number of lines is reduced from 300 to 250, lines 0 through 49 are removed, and the existing lines 50 through 299 become lines 0 through 249.

适用于