Console.WindowLeft 속성

정의

화면 버퍼에 상대적인 콘솔 창 영역의 맨 왼쪽 위치를 가져오거나 설정합니다.

public:
 static property int WindowLeft { int get(); void set(int value); };
public static int WindowLeft { get; [System.Runtime.Versioning.SupportedOSPlatform("windows")] set; }
public static int WindowLeft { get; set; }
[<set: System.Runtime.Versioning.SupportedOSPlatform("windows")>]
member this.WindowLeft : int with get, set
member this.WindowLeft : int with get, set
Public Shared Property WindowLeft As Integer

속성 값

Int32

맨 왼쪽 콘솔 창 위치(열)입니다.

특성

예외

집합 작업에서 할당할 값이 0보다 작습니다.

또는

할당 결과, WindowLeftWindowWidth의 합이 BufferWidth를 초과합니다.

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

설정 작업은 Windows 이외의 운영 체제에서 호출됩니다.

예제

다음은 80열 콘솔 창을 열고 너비가 120열인 버퍼 영역을 정의하는 예제입니다. 창 및 버퍼 크기에 대한 정보를 표시한 다음 사용자가 왼쪽 화살표 키 또는 오른쪽 화살표 키를 누를 때까지 기다립니다. 이전의 경우 결과가 법적 값인 경우 속성 값을 WindowLeft 1씩 감소합니다. 후자의 경우 결과가 합법적인 경우 속성의 WindowLeft 값을 1씩 증가합니다. 이 예제에서는 속성에 할당 WindowLeft 할 값이 음수가 아니고 속성의 합계 WindowWidth WindowLeft 가 속성 값을 초과 BufferWidth 하지 않는지 확인하므로 이 예제를 처리ArgumentOutOfRangeException할 필요가 없습니다.

using namespace System;

void ShowConsoleStatistics()
{
   Console::WriteLine("Console statistics:");
   Console::WriteLine("   Buffer: {0} x {1}", Console::BufferHeight, Console::BufferWidth);
   Console::WriteLine("   Window: {0} x {1}", Console::WindowHeight, Console::WindowWidth);
   Console::WriteLine("   Window starts at {0}.", Console::WindowLeft);
   Console::WriteLine("Press <- or -> to move window, Ctrl+C to exit.");
}

int main()
{
   ConsoleKeyInfo key;
   bool moved = false;

   Console::BufferWidth = 120;
   Console::Clear();

   ShowConsoleStatistics();
   
   do {
      key = Console::ReadKey(true);
      if (key.Key == ConsoleKey::LeftArrow)
      {
         int pos = Console::WindowLeft - 1;
         if (pos >= 0 && pos + Console::WindowWidth <= Console::BufferWidth)
         { 
            Console::WindowLeft = pos;
            moved = true;
         }       
      } 
      else if (key.Key == ConsoleKey::RightArrow)
      {
            int pos = Console::WindowLeft + 1;
            if (pos + Console::WindowWidth <= Console::BufferWidth)
            { 
               Console::WindowLeft = pos;
               moved = true;
            }
      }
      if (moved)
      { 
         ShowConsoleStatistics(); 
         moved = false;
      }   
      Console::WriteLine();
   } while (true);
}
using System;

public class Example
{
   public static void Main()
   {
      ConsoleKeyInfo key;
      bool moved = false;

      Console.BufferWidth += 4;
      Console.Clear();

      ShowConsoleStatistics();
      do
      {
         key = Console.ReadKey(true);
         if (key.Key == ConsoleKey.LeftArrow)
         {
            int pos = Console.WindowLeft - 1;
            if (pos >= 0 && pos + Console.WindowWidth <= Console.BufferWidth)
            {
               Console.WindowLeft = pos;
               moved = true;
            }
         }
         else if (key.Key == ConsoleKey.RightArrow)
         {
            int pos = Console.WindowLeft + 1;
            if (pos + Console.WindowWidth <= Console.BufferWidth)
            {
               Console.WindowLeft = pos;
               moved = true;
            }
         }
         if (moved)
         {
            ShowConsoleStatistics();
            moved = false;
         }
         Console.WriteLine();
      } while (true);
   }

   private static void ShowConsoleStatistics()
   {
      Console.WriteLine("Console statistics:");
      Console.WriteLine("   Buffer: {0} x {1}", Console.BufferHeight, Console.BufferWidth);
      Console.WriteLine("   Window: {0} x {1}", Console.WindowHeight, Console.WindowWidth);
      Console.WriteLine("   Window starts at {0}.", Console.WindowLeft);
      Console.WriteLine("Press <- or -> to move window, Ctrl+C to exit.");
   }
}
open System

let showConsoleStatistics () =
    printfn "Console statistics:"
    printfn $"   Buffer: {Console.BufferHeight} x {Console.BufferWidth}" 
    printfn $"   Window: {Console.WindowHeight} x {Console.WindowWidth}"
    printfn $"   Window starts at {Console.WindowLeft}."
    printfn "Press <- or -> to move window, Ctrl+C to exit."

Console.BufferWidth <- Console.BufferWidth + 4
Console.Clear()

showConsoleStatistics ()

let mutable moved = false

while true do
    let key = Console.ReadKey true
    if key.Key = ConsoleKey.LeftArrow then
        let pos = Console.WindowLeft - 1
        if pos >= 0 && pos + Console.WindowWidth <= Console.BufferWidth then
            Console.WindowLeft <- pos
            moved <- true
    elif key.Key = ConsoleKey.RightArrow then
        let pos = Console.WindowLeft + 1
        if pos + Console.WindowWidth <= Console.BufferWidth then
            Console.WindowLeft <- pos
            moved <- true
    if moved then
        showConsoleStatistics ()
        moved <- false
    
    printfn ""
Module Example
   Public Sub Main()
      Dim key As ConsoleKeyInfo
      Dim moved As Boolean = False
            
      Console.BufferWidth = 120
      Console.Clear()
      
      ShowConsoleStatistics()
      Do While True
         key = Console.ReadKey(True)
         If key.Key = ConsoleKey.LeftArrow Then
            Dim pos As Integer = Console.WindowLeft - 1
            If pos >= 0 And pos + Console.WindowWidth <= Console.BufferWidth Then 
               Console.WindowLeft = pos
               moved = True
            End If       
         ElseIf key.Key = ConsoleKey.RightArrow Then
            Dim pos As Integer = Console.WindowLeft + 1
            If pos + Console.WindowWidth <= Console.BufferWidth Then 
               Console.WindowLeft = pos
               moved = True
            End If
         End If
         If moved Then ShowConsoleStatistics() : moved = False
         Console.WriteLine()
      Loop
   End Sub
   
   Private Sub ShowConsoleStatistics()
      Console.WriteLine("Console statistics:")
      Console.WriteLine("   Buffer: {0} x {1}", Console.BufferHeight, Console.BufferWidth)
      Console.WriteLine("   Window: {0} x {1}", Console.WindowHeight, Console.WindowWidth)
      Console.WriteLine("   Window starts at {0}.", Console.WindowLeft)
      Console.WriteLine("Press <- or -> to move window, Ctrl+C to exit.")
   End Sub
End Module

설명

콘솔은 사각형 창을 더 큰 사각형 버퍼 영역으로 나타냅니다. 창과 버퍼는 모두 행 수와 열 수에 따라 세로로 측정됩니다. 버퍼 영역의 차원은 및 BufferWidth 속성에 BufferHeight 의해 정의됩니다. 콘솔 영역의 차원은 및 WindowWidth 속성에 WindowHeight 의해 정의됩니다. 이 속성은 WindowLeft 콘솔 창의 첫 번째 열에 표시되는 버퍼 영역의 열을 결정합니다. 속성 값의 WindowLeft 범위는 0 BufferWidth - WindowWidth에서 . 해당 범위를 ArgumentOutOfRangeException벗어난 값으로 설정하려고 하면 .

콘솔 창이 처음 열리면 속성의 WindowLeft 기본값은 0입니다. 이는 콘솔에 표시되는 첫 번째 열이 버퍼 영역의 첫 번째 열(위치 0의 열)에 해당한다는 것을 나타냅니다. 콘솔 창과 버퍼 영역의 기본 너비는 80개 열입니다. 즉, 콘솔 창이 WindowLeft 좁아지거나 버퍼 영역이 더 넓어지는 경우에만 속성을 수정할 수 있습니다.

버퍼 영역의 너비가 콘솔 창의 너비를 초과하면 사용자가 가로 스크롤 막대를 사용하여 창과 WindowLeft 버퍼 영역의 관계를 정의할 때 속성 값이 자동으로 조정됩니다.

출력이 리디렉션될 때 속성 값을 WindowLeft 설정하려고 하면 예외가 IOException throw됩니다. 예외를 방지하려면 속성이 반환false되는 경우에만 IsOutputRedirected 이 속성의 값을 설정할 수 있습니다.

적용 대상