Console.SetCursorPosition(Int32, Int32) Yöntem

Tanım

İmlecin konumunu ayarlar.

public:
 static void SetCursorPosition(int left, int top);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public static void SetCursorPosition (int left, int top);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
[System.Runtime.Versioning.UnsupportedOSPlatform("android")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static void SetCursorPosition (int left, int top);
public static void SetCursorPosition (int left, int top);
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
static member SetCursorPosition : int * int -> unit
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("android")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
static member SetCursorPosition : int * int -> unit
static member SetCursorPosition : int * int -> unit
Public Shared Sub SetCursorPosition (left As Integer, top As Integer)

Parametreler

left
Int32

İmlecin sütun konumu. Sütunlar 0'dan başlayarak soldan sağa numaralandırılır.

top
Int32

İmlecin satır konumu. Satırlar 0'dan başlayarak yukarıdan aşağıya numaralandırılır.

Öznitelikler

Özel durumlar

left veya top sıfırdan küçüktür.

-veya-

left değerinden büyük veya eşittir BufferWidth.

-veya-

top değerinden büyük veya eşittir BufferHeight.

Kullanıcının bu eylemi gerçekleştirmek için izni yok.

G/ç hatası oluştu.

Örnekler

Bu örnekte ve CursorTop özellikleri ile SetCursorPosition ve Clear yöntemleri gösterilmektedirCursorLeft. Örnek, "+", "|" ve "-" dizelerinin birleşimini kullanarak 5 karakterden 5 karakterlik bir dikdörtgen çizmek için sonraki yazma işleminin nerede gerçekleşeceğini belirleyen imleci konumlandırıyor. Dikdörtgenin diğer dizelerin bir birleşimini kullanarak daha az adım ile çizilebileceğini unutmayın.

// This example demonstrates the 
//     Console.CursorLeft and 
//     Console.CursorTop properties, and the
//     Console.SetCursorPosition and 
//     Console.Clear methods.
using namespace System;
int origRow;
int origCol;
void WriteAt( String^ s, int x, int y )
{
   try
   {
      Console::SetCursorPosition( origCol + x, origRow + y );
      Console::Write( s );
   }
   catch ( ArgumentOutOfRangeException^ e ) 
   {
      Console::Clear();
      Console::WriteLine( e->Message );
   }

}

int main()
{
   
   // Clear the screen, then save the top and left coordinates.
   Console::Clear();
   origRow = Console::CursorTop;
   origCol = Console::CursorLeft;
   
   // Draw the left side of a 5x5 rectangle, from top to bottom.
   WriteAt( "+", 0, 0 );
   WriteAt( "|", 0, 1 );
   WriteAt( "|", 0, 2 );
   WriteAt( "|", 0, 3 );
   WriteAt( "+", 0, 4 );
   
   // Draw the bottom side, from left to right.
   WriteAt( "-", 1, 4 ); // shortcut: WriteAt("---", 1, 4)
   WriteAt( "-", 2, 4 ); // ...
   WriteAt( "-", 3, 4 ); // ...
   WriteAt( "+", 4, 4 );
   
   // Draw the right side, from bottom to top.
   WriteAt( "|", 4, 3 );
   WriteAt( "|", 4, 2 );
   WriteAt( "|", 4, 1 );
   WriteAt( "+", 4, 0 );
   
   // Draw the top side, from right to left.
   WriteAt( "-", 3, 0 ); // shortcut: WriteAt("---", 1, 0)
   WriteAt( "-", 2, 0 ); // ...
   WriteAt( "-", 1, 0 ); // ...
   
   //
   WriteAt( "All done!", 0, 6 );
   Console::WriteLine();
}

/*
This example produces the following results:

+---+
|   |
|   |
|   |
+---+

All done!

*/
// This example demonstrates the
//     Console.CursorLeft and
//     Console.CursorTop properties, and the
//     Console.SetCursorPosition and
//     Console.Clear methods.
using System;

class Sample
{
    protected static int origRow;
    protected static int origCol;

    protected static void WriteAt(string s, int x, int y)
    {
    try
        {
        Console.SetCursorPosition(origCol+x, origRow+y);
        Console.Write(s);
        }
    catch (ArgumentOutOfRangeException e)
        {
        Console.Clear();
        Console.WriteLine(e.Message);
        }
    }

    public static void Main()
    {
// Clear the screen, then save the top and left coordinates.
    Console.Clear();
    origRow = Console.CursorTop;
    origCol = Console.CursorLeft;

// Draw the left side of a 5x5 rectangle, from top to bottom.
    WriteAt("+", 0, 0);
    WriteAt("|", 0, 1);
    WriteAt("|", 0, 2);
    WriteAt("|", 0, 3);
    WriteAt("+", 0, 4);

// Draw the bottom side, from left to right.
    WriteAt("-", 1, 4); // shortcut: WriteAt("---", 1, 4)
    WriteAt("-", 2, 4); // ...
    WriteAt("-", 3, 4); // ...
    WriteAt("+", 4, 4);

// Draw the right side, from bottom to top.
    WriteAt("|", 4, 3);
    WriteAt("|", 4, 2);
    WriteAt("|", 4, 1);
    WriteAt("+", 4, 0);

// Draw the top side, from right to left.
    WriteAt("-", 3, 0); // shortcut: WriteAt("---", 1, 0)
    WriteAt("-", 2, 0); // ...
    WriteAt("-", 1, 0); // ...
//
    WriteAt("All done!", 0, 6);
    Console.WriteLine();
    }
}
/*
This example produces the following results:

+---+
|   |
|   |
|   |
+---+

All done!

*/
// This example demonstrates the
//     Console.CursorLeft and
//     Console.CursorTop properties, and the
//     Console.SetCursorPosition and
//     Console.Clear methods.
open System

// Clear the screen, then save the top and left coordinates.
Console.Clear()
let origRow = Console.CursorTop
let origCol = Console.CursorLeft

let writeAt s x y =
    try
        Console.SetCursorPosition(origCol + x, origRow + y)
        printfn $"%s{s}"
    with :? ArgumentOutOfRangeException as e ->
        Console.Clear()
        printfn $"{e.Message}"

// Draw the left side of a 5x5 rectangle, from top to bottom.
writeAt "+" 0 0
writeAt "|" 0 1
writeAt "|" 0 2
writeAt "|" 0 3
writeAt "+" 0 4

// Draw the bottom side, from left to right.
writeAt "-" 1 4 // shortcut: writeAt "---", 1, 4)
writeAt "-" 2 4 // ...
writeAt "-" 3 4 // ...
writeAt "+" 4 4

// Draw the right side, from bottom to top.
writeAt "|" 4 3
writeAt "|" 4 2
writeAt "|" 4 1
writeAt "+" 4 0

// Draw the top side, from right to left.
writeAt "-" 3 0 // shortcut: writeAt "---", 1, 0)
writeAt "-" 2 0 // ...
writeAt "-" 1 0 // ...

writeAt "All done!" 0 6
printfn ""


// This example produces the following results:
//
// +---+
// |   |
// |   |
// |   |
// +---+
//
// All done!
' This example demonstrates the 
'     Console.CursorLeft and 
'     Console.CursorTop properties, and the
'     Console.SetCursorPosition and 
'     Console.Clear methods.
Class Sample
   Protected Shared origRow As Integer
   Protected Shared origCol As Integer
   
   Protected Shared Sub WriteAt(s As String, x As Integer, y As Integer)
      Try
         Console.SetCursorPosition(origCol + x, origRow + y)
         Console.Write(s)
      Catch e As ArgumentOutOfRangeException
         Console.Clear()
         Console.WriteLine(e.Message)
      End Try
   End Sub
   
   Public Shared Sub Main()
      ' Clear the screen, then save the top and left coordinates.
      Console.Clear()
      origRow = Console.CursorTop
      origCol = Console.CursorLeft
      
      ' Draw the left side of a 5x5 rectangle, from top to bottom.
      WriteAt("+", 0, 0)
      WriteAt("|", 0, 1)
      WriteAt("|", 0, 2)
      WriteAt("|", 0, 3)
      WriteAt("+", 0, 4)
      
      ' Draw the bottom side, from left to right.
      WriteAt("-", 1, 4) ' shortcut: WriteAt("---", 1, 4)
      WriteAt("-", 2, 4) ' ...
      WriteAt("-", 3, 4) ' ...
      WriteAt("+", 4, 4)
      
      ' Draw the right side, from bottom to top.
      WriteAt("|", 4, 3)
      WriteAt("|", 4, 2)
      WriteAt("|", 4, 1)
      WriteAt("+", 4, 0)
      
      ' Draw the top side, from right to left.
      WriteAt("-", 3, 0) ' shortcut: WriteAt("---", 1, 0)
      WriteAt("-", 2, 0) ' ...
      WriteAt("-", 1, 0) ' ...
      '
      WriteAt("All done!", 0, 6)
      Console.WriteLine()
   End Sub
End Class
'
'This example produces the following results:
'
'+---+
'|   |
'|   |
'|   |
'+---+
'
'All done!
'

Açıklamalar

SetCursorPosition Konsol penceresinde bir sonraki yazma işleminin nerede başlayacağını belirtmek için yöntemini kullanın. Belirtilen imleç konumu konsol penceresinde o anda görünen alanın dışındaysa, pencere başlangıcı imleci görünür hale getirmek için otomatik olarak değişir.

konsol penceresine her karakter yazıldıktan sonra imleç otomatik olarak bir sonraki karakter konumuna geçer. İmleç konsol penceresinin sağ alt karakter konumundaysa, sonraki yazma işlemi konsol penceresinin kaydırılıp imlecin görünür kalmasını sağlar. Konsol penceresinin kaydırmasına neden olmadan sağ alt karakter konumuna bir karakter yazmak istiyorsanız, bir karakteri bu konuma taşımak için yöntemini kullanın MoveBufferArea .

Şunlara uygulanır