Console.WindowWidth 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
콘솔 창의 컨트롤의 너비를 가져오거나 설정합니다.
public:
static property int WindowWidth { int get(); void set(int value); };
public static int WindowWidth { [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] get; [System.Runtime.Versioning.SupportedOSPlatform("windows")] set; }
public static int WindowWidth { [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] [System.Runtime.Versioning.UnsupportedOSPlatform("android")] [System.Runtime.Versioning.UnsupportedOSPlatform("ios")] [System.Runtime.Versioning.UnsupportedOSPlatform("tvos")] get; [System.Runtime.Versioning.SupportedOSPlatform("windows")] set; }
[System.Runtime.Versioning.UnsupportedOSPlatform("android")]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static int WindowWidth { get; set; }
public static int WindowWidth { get; set; }
[<get: System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
[<set: System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member WindowWidth : int with get, set
[<get: System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
[<set: System.Runtime.Versioning.SupportedOSPlatform("windows")>]
[<get: System.Runtime.Versioning.UnsupportedOSPlatform("android")>]
[<get: System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<get: System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
static member WindowWidth : int with get, set
[<System.Runtime.Versioning.UnsupportedOSPlatform("android")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
static member WindowWidth : int with get, set
static member WindowWidth : int with get, set
Public Shared Property WindowWidth As Integer
속성 값
콘솔 창의 너비(열)입니다.
- 특성
예외
WindowWidth 속성 값 또는 WindowHeight 속성 값이 0보다 작거나 같습니다.
또는
속성 값과 WindowHeight 속성 값 WindowTop 이 Int16.MaxValue보다 크거나 같습니다.
또는
WindowWidth 속성 값 또는 WindowHeight 속성 값이 현재 화면 해상도 및 콘솔 글꼴에 가장 클 수 있는 창의 너비 또는 높이보다 큽니다.
정보를 읽거나 쓰는 동안 오류가 발생했습니다.
설정 작업은 Windows 이외의 운영 체제에서 호출됩니다.
예제
이 예제에서는 SetWindowSize 메서드 및 WindowWidth 및 WindowHeight 속성을 보여 줍니다. 콘솔 창 크기를 변경하는 전체 효과를 보려면 예제를 실행해야 합니다.
이 예제에서는 85개의 열과 43개의 행으로 설정된 콘솔 창의 크기를 보고한 다음 키 누름을 기다립니다. 키를 누르면 콘솔 창의 크기가 반으로 줄고, 새 차원이 보고되고, 예제에서 다른 키 누름을 기다립니다. 마지막으로 키를 누르면 콘솔 창이 원래 차원으로 복원되고 예제가 종료됩니다.
// 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.
open System
//
// Step 1: Get the current window dimensions.
//
let origWidth = Console.WindowWidth
let origHeight = Console.WindowHeight
printfn $"The current window width is {Console.WindowWidth}, and the current window height is {Console.WindowHeight}."
printfn " (Press any key to continue...)"
Console.ReadKey true |> ignore
//
// Step 2: Cut the window to 1/4 its original size.
//
let width = origWidth / 2
let height = origHeight / 2
Console.SetWindowSize(width, height)
printfn $"The new window width is {Console.WindowWidth}, and the new window height is {Console.WindowHeight}."
printfn " (Press any key to continue...)"
Console.ReadKey true |> ignore
//
// Step 3: Restore the window to its original size.
//
Console.SetWindowSize(origWidth, origHeight)
printfn $"The current window width is {Console.WindowWidth}, and the current window height is {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 설정하려고 하면 또는 예외가 ArgumentOutOfRangeExceptionIOException throw됩니다. 예외를 방지하려면 속성이 를 반환false
하는 경우에만 IsOutputRedirected 이 속성의 값을 설정할 수 있습니다.
적용 대상
.NET