Console.SetCursorPosition メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Console.SetCursorPosition メソッドの意味・解説 

Console.SetCursorPosition メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

カーソル位置設定します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Shared Sub SetCursorPosition
 ( _
    left As Integer, _
    top As Integer _
)
Dim left As Integer
Dim top As Integer

Console.SetCursorPosition(left, top)
public static void SetCursorPosition
 (
    int left,
    int top
)
public:
static void SetCursorPosition (
    int left, 
    int top
)
public static void SetCursorPosition
 (
    int left, 
    int top
)
public static function SetCursorPosition
 (
    left : int, 
    top : int
)

パラメータ

left

カーソルを置く列の位置

top

カーソルを置く行の位置

例外例外
例外種類条件

ArgumentOutOfRangeException

left または top が 0 未満です。

または

left が BufferWidth 以上です。

または

top が BufferHeight 以上です。

SecurityException

ユーザーに、この操作実行するためのアクセス許可がありません。

IOException

I/O エラー発生しました

解説解説
使用例使用例

CursorLeft プロパティと CursorTop プロパティ、および SetCursorPosition メソッドClear メソッド使用例次に示します。この例では、次のテキスト書き込み位置となるカーソル適宜配置することによって、"+"、"|"、"-" の文字列使いながら 5 文字 × 5 文字四角形描画しています。他の文字列組み合わせれば、より少なステップ数四角形描画できます

' This example demonstrates the 
'     Console.CursorLeft and 
'     Console.CursorTop properties, and the
'     Console.SetCursorPosition and 
'     Console.Clear methods.
Imports System

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 'WriteAt
   
   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 'Main
End Class 'Sample
'
'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.
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.

import 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.get_Message());
        }
    } //WriteAt

    public static void main(String[]
 args)
    {
        // Clear the screen, then save the top and left coordinates.
        Console.Clear();
        origRow = Console.get_CursorTop();
        origCol = Console.get_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();
    } //main
} //Sample
/*
This example produces the following results:

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

All done!

*/
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「Console.SetCursorPosition メソッド」の関連用語

Console.SetCursorPosition メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Console.SetCursorPosition メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS