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

Définition

Définit la hauteur et la largeur de la fenêtre de console sur les valeurs spécifiées.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)

Paramètres

width
Int32 Int32 Int32 Int32

Largeur de la fenêtre de console mesurée en colonnes.The width of the console window measured in columns.

height
Int32 Int32 Int32 Int32

Hauteur de la fenêtre de console mesurée en lignes.The height of the console window measured in rows.

Exceptions

width ou height est inférieur ou égal à zéro.width or height is less than or equal to zero.

- ou --or- width plus WindowLeft ou height plus WindowTop est supérieur ou égal à MaxValue.width plus WindowLeft or height plus WindowTop is greater than or equal to MaxValue.

- ou --or- width ou height est supérieur à la plus grande largeur ou hauteur de fenêtre possible compte tenu de la police de la console et de la résolution d’écran actuellement définies.width or height is greater than the largest possible window width or height for the current screen resolution and console font.

L’utilisateur n’est pas autorisé à effectuer cette action.The user does not have permission to perform this action.

Une erreur d'E/S s'est produite.An I/O error occurred.

Le système d’exploitation actuel n’est pas Windows.The current operating system is not Windows.

Exemples

Cet exemple illustre la SetWindowSize méthode, ainsi que WindowWidth les WindowHeight propriétés et.This example demonstrates the SetWindowSize method, and the WindowWidth and WindowHeight properties. Vous devez exécuter l’exemple pour voir complètement l’effet de la modification de la taille de la fenêtre de la console.You must run the example to see the full effect of changing the console window size.

L’exemple signale les dimensions d’une fenêtre de console définie sur 85 colonnes et 43 lignes, puis attend qu’une touche soit enfoncée.The example reports the dimensions of a console window set to 85 columns and 43 rows, then waits for a key to be pressed. Quand une touche est enfoncée, les dimensions de la fenêtre de console sont divisées en deux, les nouvelles dimensions sont signalées, et l’exemple attend une autre pression sur une touche.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. Enfin, lorsqu’une touche est enfoncée, la fenêtre de console est restaurée à ses dimensions d’origine et l’exemple se termine.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.
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
End Class
'
'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.
'
'

Sécurité

UIPermission
pour modifier les fenêtres de niveau supérieur et les sous-fenêtres sécurisées.for modifying safe top-level windows and subwindows. Énumération associée:SafeTopLevelWindowsAssociated enumeration: SafeTopLevelWindows

S’applique à