Console.WindowHeight Eigenschaft

Definition

Ruft die Höhe des Konsolenfensterbereichs ab oder legt diese fest.Gets or sets the height of the console window area.

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

Eigenschaftswert

Die Höhe des Konsolenfensters in Zeilen.The height of the console window measured in rows.

Ausnahmen

Der Wert der WindowWidth-Eigenschaft oder der Wert der WindowHeight-Eigenschaft muss kleiner als oder gleich 0 sein.The value of the WindowWidth property or the value of the WindowHeight property is less than or equal to 0.

Oder-or- Der Wert der WindowHeight-Eigenschaft plus dem Wert der WindowTop-Eigenschaft muss größer als oder gleich MaxValue sein.The value of the WindowHeight property plus the value of the WindowTop property is greater than or equal to MaxValue.

Oder-or- Der Wert der WindowWidth-Eigenschaft oder der Wert der WindowHeight-Eigenschaft ist größer als die größtmögliche Fensterbreite oder -höhe für die aktuelle Bildschirmauflösung und Konsolenschriftart.The value of the WindowWidth property or the value of the WindowHeight property is greater than the largest possible window width or height for the current screen resolution and console font.

Fehler beim Lesen oder Schreiben von Informationen.Error reading or writing information.

Der set-Vorgang wird unter einem anderen Betriebssystem als Windows aufgerufen.The set operation is invoked on an operating system other than Windows.

Beispiele

In diesem Beispiel werden die SetWindowSize-Methode und die Eigenschaften WindowWidth und WindowHeight veranschaulicht.This example demonstrates the SetWindowSize method, and the WindowWidth and WindowHeight properties. Sie müssen das Beispiel ausführen, um die vollständige Auswirkung der Änderung der Größe des Konsolenfensters anzuzeigen.You must run the example to see the full effect of changing the console window size.

Das Beispiel meldet die Abmessungen eines Konsolenfensters, das auf 85 Spalten und 43 Zeilen festgelegt ist, und wartet dann auf einen Tastendruck.The example reports the dimensions of a console window set to 85 columns and 43 rows, then waits for a key press. Wenn eine Taste gedrückt wird, werden die Abmessungen des Konsolenfensters halbiert, die neuen Dimensionen werden gemeldet, und das Beispiel wartet auf einen anderen Tastendruck.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. Wenn eine Taste gedrückt wird, wird das Konsolenfenster in den ursprünglichen Dimensionen wieder hergestellt, und das Beispiel wird beendet.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.
'
'

Hinweise

Wenn Sie versuchen, den Wert der WindowHeight-Eigenschaft festzulegen, wenn die Ausgabe umgeleitet wird, wird entweder eine ArgumentOutOfRangeException oder eine IOException Ausnahme ausgelöst.Attempting to set the value of the WindowHeight property when output is redirected throws either an ArgumentOutOfRangeException or an IOException exception. Um eine Ausnahme zu verhindern, können Sie den Wert dieser Eigenschaft nur festlegen, wenn die IsOutputRedirected-Eigenschaft falsezurückgibt.To prevent an exception, you can set the value of this property only if the IsOutputRedirected property returns false.

Gilt für: