Console.SetWindowSize(Int32, Int32) Console.SetWindowSize(Int32, Int32) Console.SetWindowSize(Int32, Int32) Console.SetWindowSize(Int32, Int32) Method

Definición

Establece el alto y el ancho de la ventana de la consola en los valores especificados.Sets the height and width of the console window to the specified values.

public:
 static void SetWindowSize(int width, int height);
public static void SetWindowSize (int width, int height);
static member SetWindowSize : int * int -> unit
Public Shared Sub SetWindowSize (width As Integer, height As Integer)

Parámetros

width
Int32 Int32 Int32 Int32

Ancho de la ventana de la consola, medido en columnas.The width of the console window measured in columns.

height
Int32 Int32 Int32 Int32

Alto de la ventana de la consola, medido en filas.The height of the console window measured in rows.

Excepciones

width o height es menor o igual que cero.width or height is less than or equal to zero.

o bien-or- width más WindowLeft o height más WindowTop es mayor o igual que MaxValue.width plus WindowLeft or height plus WindowTop is greater than or equal to MaxValue.

O bien-or- 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.width or height is greater than the largest possible window width or height for the current screen resolution and console font.

El usuario no tiene permiso para realizar esta acción.The user does not have permission to perform this action.

Error de E/S.An I/O error occurred.

El sistema operativo actual no es Windows.The current operating system is not Windows.

Ejemplos

En este ejemplo se SetWindowSize muestra el método y WindowWidth las WindowHeight propiedades y.This example demonstrates the SetWindowSize method, and the WindowWidth and WindowHeight properties. Debe ejecutar el ejemplo para ver el efecto completo de cambiar el tamaño de la ventana de la consola.You must run the example to see the full effect of changing the console window size.

En el ejemplo se notifican las dimensiones de una ventana de consola establecida en 85 columnas y 43 filas y, a continuación, se espera a que se presione una tecla.The example reports the dimensions of a console window set to 85 columns and 43 rows, then waits for a key to be pressed. Cuando se presiona una tecla, se muestran las dimensiones de la ventana de la consola, se registran las nuevas dimensiones y el ejemplo espera a que se presione otra tecla.When any key is pressed, the dimensions of the console window are halved, the new dimensions are reported, and the example waits for another key press. Por último, cuando se presiona una tecla, la ventana de la consola se restaura a sus dimensiones originales y el ejemplo finaliza.Finally, when any key is pressed, the console window is restored to its original dimensions and the example terminates.

// This example demonstrates the Console.SetWindowSize method,
//                           the Console.WindowWidth property, 
//                       and the Console.WindowHeight property.
using namespace System;
int main()
{
   int origWidth;
   int width;
   int origHeight;
   int 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.

*/
// 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.

*/
' This example demonstrates the Console.SetWindowSize method,
'                           the Console.WindowWidth property, 
'                       and the Console.WindowHeight property.
Imports System

Class Sample
   Public Shared Sub Main()
      Dim origWidth, width As Integer
      Dim origHeight, height As Integer
      Dim m1 As String = "The current window width is {0}, and the " & _
                         "current window height is {1}."
      Dim m2 As String = "The new window width is {0}, and the new " & _
                         "window height is {1}."
      Dim m4 As String = "  (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)
   End Sub 'Main
End Class 'Sample
'
'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.
'
'

Seguridad

UIPermission
para modificar ventanas y subventanas seguras de nivel superior.for modifying safe top-level windows and subwindows. Enumeración asociada:SafeTopLevelWindowsAssociated enumeration: SafeTopLevelWindows

Se aplica a