Console.WindowWidth Console.WindowWidth Console.WindowWidth Console.WindowWidth Property

정의

콘솔 창의 컨트롤의 너비를 가져오거나 설정합니다.Gets or sets the width of the console window.

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

속성 값

콘솔 창의 너비(열)입니다.The width of the console window measured in columns.

예외

WindowWidth 속성 값 또는 WindowHeight 속성 값이 0보다 작거나 같습니다.The value of the WindowWidth property or the value of the WindowHeight property is less than or equal to 0.

또는-or- WindowHeight 속성 값과 WindowTop 속성 값의 합이 MaxValue보다 크거나 같습니다.The value of the WindowHeight property plus the value of the WindowTop property is greater than or equal to MaxValue.

또는-or- WindowWidth 속성 값 또는 WindowHeight 속성 값이 현재 화면 해상도 및 콘솔 글꼴에 가장 클 수 있는 창의 너비 또는 높이보다 큽니다.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.

정보를 읽거나 쓰는 동안 오류가 발생했습니다.Error reading or writing information.

설정 작업은 Windows 이외의 운영 체제에서 호출됩니다.The set operation is invoked on an operating system other than Windows.

예제

이 예제에서는 합니다 SetWindowSize 메서드 및 WindowWidthWindowHeight 속성입니다.This example demonstrates the SetWindowSize method, and the WindowWidth and WindowHeight properties. 콘솔 창 크기를 변경 하는 모든 결과 보려면이 예제를 실행 해야 합니다.You must run the example to see the full effect of changing the console window size.

이 예제에서는 85 열과 43 행으로 설정 하는 콘솔 창의 크기를 보고 키를 누를 때까지 기다립니다.The example reports the dimensions of a console window set to 85 columns and 43 rows, then waits for a key press. 모든 키를 누르면 콘솔 창의 크기는 50% 감소, 새로 차원을 보고 되 고이 예제에서는 다른 키를 누를 때까지 대기 합니다.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. 마지막으로, 모든 키를 누를 때 콘솔 창 원래 크기로 복원 되 고 예제를 종료 합니다.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.
'
'

설명

값을 설정 하려고 합니다 WindowWidth 출력을 리디렉션할 때 속성 중 하나를 throw 합니다.는 ArgumentOutOfRangeException 또는 IOException 예외입니다.Attempting to set the value of the WindowWidth property when output is redirected throws either an ArgumentOutOfRangeException or an IOException exception. 예외를 방지 하려면 경우에만이 속성의 값을 설정할 수 있습니다 합니다 IsOutputRedirected 속성이 반환 false합니다.To prevent an exception, you can set the value of this property only if the IsOutputRedirected property returns false.

적용 대상