Console.WindowLeft Özellik

Tanım

Konsol penceresi alanının ekran arabelleğine göre en soldaki konumunu alır veya ayarlar.

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

Özellik Değeri

Int32

Sütunlarda ölçülen en soldaki konsol penceresi konumu.

Öznitelikler

Özel durumlar

Ayarlanmış bir işlemde, atanacak değer sıfırdan küçüktür.

-veya-

Atamanın sonucunda artı WindowWidth değeri WindowLeft aşılırBufferWidth.

Bilgi okuma veya yazma hatası.

Küme işlemi Windows dışında bir işletim sisteminde çağrılır.

Örnekler

Aşağıdaki örnek 80 sütunlu bir konsol penceresi açar ve 120 sütun genişliğinde bir arabellek alanı tanımlar. Pencere ve arabellek boyutuyla ilgili bilgileri görüntüler ve ardından kullanıcının SOL OK tuşuna veya SAĞ OK tuşuna basmasını bekler. Önceki örnekte, sonucun yasal bir değer olması durumunda özelliğin WindowLeft değerini bir azaltma. İkinci durumda, sonucun yasal olması durumunda özelliğin WindowLeft değerini bir artırır. Örneğin, özelliğine atanacak WindowLeft değerin negatif olmadığını denetlediğinden ve özelliklerinin toplamının WindowWidth WindowLeft özellik değerini aşmasına BufferWidth neden olmadığından bir ArgumentOutOfRangeExceptionişlemek zorunda olmadığını unutmayın.

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

Açıklamalar

Konsol, daha büyük bir dikdörtgen arabellek alanına dikdörtgen bir pencereyi temsil eder. Hem pencere hem de arabellek, satır sayısına göre dikey olarak ve sütun sayısına göre yatay olarak ölçülür. Arabellek alanının boyutları ve BufferWidth özellikleri tarafından BufferHeight tanımlanır. Konsol alanının boyutları ve WindowWidth özellikleri tarafından WindowHeight tanımlanır. WindowLeft özelliği, konsol penceresinin ilk sütununda arabellek alanının hangi sütununun görüntüleneceğini belirler. özelliğinin WindowLeft değeri 0 BufferWidth - WindowWidthile arasında değişebilir. Bu aralığın dışındaki bir değere ayarlanma girişimi bir ArgumentOutOfRangeExceptionoluşturur.

Bir konsol penceresi ilk kez açıldığında, özelliğin WindowLeft varsayılan değeri sıfırdır ve bu da konsol tarafından gösterilen ilk sütunun arabellek alanındaki ilk sütuna (sıfır konumundaki sütun) karşılık geldiğini gösterir. Hem konsol penceresinin hem de arabellek alanının varsayılan genişliği 80 sütundur. Bu, özelliğin WindowLeft yalnızca konsol penceresinin daraltılması veya arabellek alanının daha geniş olması durumunda değiştirilebileceği anlamına gelir.

Arabellek alanının genişliği konsol penceresinin genişliğini aşarsa, kullanıcı pencerenin arabellek alanıyla ilişkisini tanımlamak için yatay kaydırma çubuğunu kullandığında özelliğin değeri WindowLeft otomatik olarak ayarlanır.

Çıkış yeniden yönlendirildiğinde özelliğin WindowLeft değerini ayarlamaya çalışmak bir IOException özel durum oluşturur. Özel durumu önlemek için, yalnızca özelliği döndürdüğünde falsebu özelliğin IsOutputRedirected değerini ayarlayabilirsiniz.

Şunlara uygulanır