Console.SetWindowSize(Int32, Int32) Método

Definición

Establece el alto y el ancho de la ventana de la consola en los valores especificados.

[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static void SetWindowSize (int width, int height);
[System.Runtime.Versioning.UnsupportedOSPlatform("android")]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static void SetWindowSize (int width, int height);
public static void SetWindowSize (int width, int height);

Parámetros

width
Int32

Ancho de la ventana de la consola, medido en columnas.

height
Int32

Alto de la ventana de la consola, medido en filas.

Atributos

Excepciones

width o height es menor o igual que cero.

o bien

widthplus o height plus WindowTopWindowLeft es mayor o igual que Int16.MaxValue.

o bien

width o height es mayor que el mayor ancho o la altura de ventana más grande posible para la resolución de pantalla y la fuente de consola actuales.

El usuario no tiene permiso para realizar esta acción.

Error de E/S.

El sistema operativo actual no es Windows.

Ejemplos

En este ejemplo se muestra el SetWindowSize método y las WindowWidth propiedades y WindowHeight . Debe ejecutar el ejemplo para ver el efecto completo de cambiar el tamaño de la ventana de la consola.

En el ejemplo se notifican las dimensiones de una ventana de consola establecida en 85 columnas y 43 filas y, a continuación, espera a que se presione una tecla. Cuando se presiona cualquier tecla, se reducen las dimensiones de la ventana de la consola, se notifican las nuevas dimensiones y el ejemplo espera otra pulsación de tecla. Por último, cuando se presiona cualquier tecla, la ventana de la consola se restaura a sus dimensiones originales y el ejemplo finaliza.

// This example demonstrates the Console.SetWindowSize method,
//                           the Console.WindowWidth property,
//                       and the Console.WindowHeight property.
using System;

class Sample
{
    public static void Main()
    {
    int origWidth, width;
    int origHeight, height;
    string m1 = "The current window width is {0}, and the " +
                "current window height is {1}.";
    string m2 = "The new window width is {0}, and the new " +
                "window height is {1}.";
    string m4 = "  (Press any key to continue...)";
//
// Step 1: Get the current window dimensions.
//
    origWidth  = Console.WindowWidth;
    origHeight = Console.WindowHeight;
    Console.WriteLine(m1, Console.WindowWidth,
                          Console.WindowHeight);
    Console.WriteLine(m4);
    Console.ReadKey(true);
//
// Step 2: Cut the window to 1/4 its original size.
//
    width  = origWidth/2;
    height = origHeight/2;
    Console.SetWindowSize(width, height);
    Console.WriteLine(m2, Console.WindowWidth,
                          Console.WindowHeight);
    Console.WriteLine(m4);
    Console.ReadKey(true);
//
// Step 3: Restore the window to its original size.
//
    Console.SetWindowSize(origWidth, origHeight);
    Console.WriteLine(m1, Console.WindowWidth,
                          Console.WindowHeight);
    }
}
/*
This example produces the following results:

The current window width is 85, and the current window height is 43.
  (Press any key to continue...)
The new window width is 42, and the new window height is 21.
  (Press any key to continue...)
The current window width is 85, and the current window height is 43.

*/

Se aplica a

Producto Versiones
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1