Console.SetBufferSize(Int32,Int32)方法用于将屏幕缓冲区的高度和宽度设置为指定的值。
Syntax: public static void SetBufferSize(int width, int height);
Parameters:
width: It sets the width of the buffer area measured in the form of columns.
height: It sets the height of the buffer area measured in the form of rows.
Return value: The new size of the buffer screen.
例外情况:
- ArgumentOutOfRangeException :如果高度或宽度小于或等于零,或者高度或宽度大于或等于MaxValue 。另外,如果宽度小于
WindowLeft + WindowWidth
或高度小于WindowTop + WindowHeight
那么我们将得到相同的异常。 - IOException :如果发生I / O错误。
注意:在下面的示例中,您将通过水平和垂直滚动条看到,因为我们给出了不同的尺寸,所以我们得到了不同大小的窗口。
范例1:
// C# program to demonstrate
// the SetBufferSize Method
using System;
using System.Text;
using System.IO;
class GFG {
// Main Method
public static void Main()
{
// using the method
Console.SetBufferSize(800, 800);
Console.WriteLine("Start");
while (true)
{
Console.WriteLine("Great Geek's Example!!!");
}
} // end Main
}
输出:
范例2:
// C# program to demonstrate
// the SetBufferSize Method
using System;
using System.Text;
using System.IO;
class GFG {
// Main Method
public static void Main()
{
Console.SetBufferSize(0, 80);
Console.WriteLine("Great Geek's Example!!!");
Console.WriteLine("The Width's value is too less!");
} // end Main
}
范例3:
// C# program to demonstrate
// the SetBufferSize Method
using System;
using System.Text;
using System.IO;
class GFG {
// Main Method
public static void Main()
{
Console.SetBufferSize(8000, -80);
Console.WriteLine("Great Geek's Example!!!");
Console.WriteLine("The negativity of this height is unbearable!");
} // end Main
}
参考:
- https://docs.microsoft.com/zh-cn/dotnet/api/system.console.setbuffersize?view=netframework-4.7.2