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

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

Console.SetBufferSize メソッド

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

画面バッファ領域の高さと幅を指定された値に設定します

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

Public Shared Sub SetBufferSize
 ( _
    width As Integer, _
    height As Integer _
)
public static void SetBufferSize
 (
    int width,
    int height
)
public:
static void SetBufferSize (
    int width, 
    int height
)
public static void SetBufferSize
 (
    int width, 
    int height
)
public static function SetBufferSize
 (
    width : int, 
    height : int
)

パラメータ

width

列数で指定されバッファ領域の幅。

height

行数指定されバッファ領域の高さ。

例外例外
例外種類条件

ArgumentOutOfRangeException

height または width が 0 以下です。

または

height または width に、Int16.MaxValue と同じかそれを超える値が指定されています。

または

width が WindowLeft と WindowWidth を合わせた値を下回ってます。

または

height が WindowTop と WindowHeight を合わせた値を下回ってます。

SecurityException

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

IOException

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

使用例使用例

WindowLeftWindowTopWindowWidthWindowHeight、BufferWidth、BufferHeight、CursorVisible の各プロパティ、および SetWindowPosition、SetBufferSize、ReadKey の各メソッド使用例次に示します。この例は、画面バッファの幅に基づいて画面バッファ内にグリッド パターン描画するものです。特定のコンソール キー (↑、↓、←、または →) が押され場合は、そのキーに応じてコンソール ウィンドウ移動します。このグリッド パターンを見ると、画面バッファ対すコンソール ウィンドウ相対的な動き確認できます

' This example demonstrates the Console.WindowLeft and
'                               Console.WindowTop properties.
Imports System
Imports System.Text
Imports System.IO
Imports Microsoft.VisualBasic

Class Sample
   Public Shared saveBufferWidth As
 Integer
   Public Shared saveBufferHeight As
 Integer
   Public Shared saveWindowHeight As
 Integer
   Public Shared saveWindowWidth As
 Integer
   Public Shared saveCursorVisible As
 Boolean
   
   Public Shared Sub Main()
      Dim m1 As String =
 _
          "1) Press the cursor keys to move the console window."
 & vbCrlf & _
          "2) Press any key to begin. When
 you're finished..."   & vbCrlf & _
          "3) Press the Escape key to quit."
      Dim g1 As String =
 "+----"
      Dim g2 As String =
 "|    "
      Dim grid1 As String
      Dim grid2 As String
      Dim sbG1 As New StringBuilder()
      Dim sbG2 As New StringBuilder()
      Dim cki As ConsoleKeyInfo
      Dim y As Integer
      '
      Try
         saveBufferWidth = Console.BufferWidth
         saveBufferHeight = Console.BufferHeight
         saveWindowHeight = Console.WindowHeight
         saveWindowWidth = Console.WindowWidth
         saveCursorVisible = Console.CursorVisible
         '
         Console.Clear()
         Console.WriteLine(m1)
         Console.ReadKey(True)
         
         ' Set the smallest possible window size before setting the
 buffer size.
         Console.SetWindowSize(1, 1)
         Console.SetBufferSize(80, 80)
         Console.SetWindowSize(40, 20)
         
         ' Create grid lines to fit the buffer. (The buffer width is
 80, but
         ' this same technique could be used with an arbitrary buffer
 width.)
         For y = 0 To (Console.BufferWidth
 / g1.Length) - 1
            sbG1.Append(g1)
            sbG2.Append(g2)
         Next y
         sbG1.Append(g1, 0, Console.BufferWidth Mod g1.Length)
         sbG2.Append(g2, 0, Console.BufferWidth Mod g2.Length)
         grid1 = sbG1.ToString()
         grid2 = sbG2.ToString()
         
         Console.CursorVisible = False
         Console.Clear()
         For y = 0 To (Console.BufferHeight
 - 2)
            If y Mod 3 = 0 Then
               Console.Write(grid1)
            Else
               Console.Write(grid2)
            End If
         Next y 
         '
         Console.SetWindowPosition(0, 0)
         Do
            cki = Console.ReadKey(True)
            Select Case cki.Key
               Case ConsoleKey.LeftArrow
                  If Console.WindowLeft > 0 Then
                     Console.SetWindowPosition(Console.WindowLeft - 1, Console.WindowTop)
                  End If
               Case ConsoleKey.UpArrow
                  If Console.WindowTop > 0 Then
                     Console.SetWindowPosition(Console.WindowLeft, Console.WindowTop
 - 1)
                  End If
               Case ConsoleKey.RightArrow
                  If Console.WindowLeft < Console.BufferWidth
 - Console.WindowWidth Then
                     Console.SetWindowPosition(Console.WindowLeft + 1, Console.WindowTop)
                  End If
               Case ConsoleKey.DownArrow
                  If Console.WindowTop < Console.BufferHeight
 - Console.WindowHeight Then
                     Console.SetWindowPosition(Console.WindowLeft, Console.WindowTop
 + 1)
                  End If
            End Select
         Loop While cki.Key <> ConsoleKey.Escape
      ' end do-while
      ' end try
      Catch e As IOException
         Console.WriteLine(e.Message)
      Finally
         Console.Clear()
         Console.SetWindowSize(1, 1)
         Console.SetBufferSize(saveBufferWidth, saveBufferHeight)
         Console.SetWindowSize(saveWindowWidth, saveWindowHeight)
         Console.CursorVisible = saveCursorVisible
      End Try
   End Sub 'Main ' end Main
End Class 'Sample ' end Sample
'
'This example produces results similar to the following:
'
'1) Press the cursor keys to move the console window.
'2) Press any key to begin. When you're finished...
'3) Press the Escape key to quit.
'
'...
'
'+----+----+----+-
'|    |    |    |
'|    |    |    |
'+----+----+----+-
'|    |    |    |
'|    |    |    |
'+----+----+----+-
'
// This example demonstrates the Console.WindowLeft and
//                               Console.WindowTop properties.
using System;
using System.Text;
using System.IO;
//
class Sample 
{
    public static int saveBufferWidth;
    public static int saveBufferHeight;
    public static int saveWindowHeight;
    public static int saveWindowWidth;
    public static bool saveCursorVisible;
//
    public static void Main()
 
    {
    string m1 = "1) Press the cursor keys to move the console
 window.\n" +
                "2) Press any key to begin. When you're finished...\n"
 +
                "3) Press the Escape key to quit.";
    string g1 = "+----";
    string g2 = "|    ";
    string grid1;
    string grid2;
    StringBuilder sbG1 = new StringBuilder();
    StringBuilder sbG2 = new StringBuilder();
    ConsoleKeyInfo cki;
    int y;
//
    try 
    {
    saveBufferWidth  = Console.BufferWidth;
    saveBufferHeight = Console.BufferHeight;
    saveWindowHeight = Console.WindowHeight;
    saveWindowWidth  = Console.WindowWidth;
    saveCursorVisible = Console.CursorVisible;
//
    Console.Clear();
    Console.WriteLine(m1);
    Console.ReadKey(true);

// Set the smallest possible window size before setting the buffer size.
    Console.SetWindowSize(1, 1);
    Console.SetBufferSize(80, 80);
    Console.SetWindowSize(40, 20);

// Create grid lines to fit the buffer. (The buffer width is 80, but
// this same technique could be used with an arbitrary buffer width.)
    for (y = 0; y < Console.BufferWidth/g1.Length; y++)
        {
        sbG1.Append(g1);
        sbG2.Append(g2);
        }
    sbG1.Append(g1, 0, Console.BufferWidth%g1.Length);
    sbG2.Append(g2, 0, Console.BufferWidth%g2.Length);
    grid1 = sbG1.ToString();
    grid2 = sbG2.ToString();

    Console.CursorVisible = false;
    Console.Clear();
    for (y = 0; y < Console.BufferHeight-1; y++)
        {
        if (y%3 == 0)
            Console.Write(grid1);
        else
            Console.Write(grid2);
        }

    Console.SetWindowPosition(0, 0);
    do
        {
        cki = Console.ReadKey(true);
        switch (cki.Key) 
            {
            case ConsoleKey.LeftArrow:
                if (Console.WindowLeft > 0) 
                    Console.SetWindowPosition(
                            Console.WindowLeft-1, Console.WindowTop);
                break;
            case ConsoleKey.UpArrow:
                if (Console.WindowTop > 0) 
                    Console.SetWindowPosition(
                            Console.WindowLeft, Console.WindowTop-1);
                break;
            case ConsoleKey.RightArrow:
                if (Console.WindowLeft < (Console.BufferWidth-Console.WindowWidth))
 
                    Console.SetWindowPosition(
                            Console.WindowLeft+1, Console.WindowTop);
                break;
            case ConsoleKey.DownArrow:
                if (Console.WindowTop < (Console.BufferHeight-Console.WindowHeight))
 
                    Console.SetWindowPosition(
                            Console.WindowLeft, Console.WindowTop+1);
                break;
            }
        } 
    while (cki.Key != ConsoleKey.Escape);  // end
 do-while
    } // end try
    catch (IOException e) 
        {
        Console.WriteLine(e.Message);
        }
    finally 
        {
        Console.Clear();
        Console.SetWindowSize(1, 1);
        Console.SetBufferSize(saveBufferWidth, saveBufferHeight);
        Console.SetWindowSize(saveWindowWidth, saveWindowHeight);
        Console.CursorVisible = saveCursorVisible;
        }
    } // end Main
} // end Sample
/*
This example produces results similar to the following:

1) Press the cursor keys to move the console window.
2) Press any key to begin. When you're finished...
3) Press the Escape key to quit.

...

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

*/
// This example demonstrates the Console.WindowLeft and
//                               Console.WindowTop properties.
using namespace System;
using namespace System::Text;
using namespace System::IO;

//
int saveBufferWidth;
int saveBufferHeight;
int saveWindowHeight;
int saveWindowWidth;
bool saveCursorVisible;

//
int main()
{
   String^ m1 = "1) Press the cursor keys to move the console window.\n"
   "2) Press any key to begin. When you're finished...\n"
   "3) Press the Escape key to quit.";
   String^ g1 = "+----";
   String^ g2 = "|    ";
   String^ grid1;
   String^ grid2;
   StringBuilder^ sbG1 = gcnew StringBuilder;
   StringBuilder^ sbG2 = gcnew StringBuilder;
   ConsoleKeyInfo cki;
   int y;
   
   //
   try
   {
      saveBufferWidth = Console::BufferWidth;
      saveBufferHeight = Console::BufferHeight;
      saveWindowHeight = Console::WindowHeight;
      saveWindowWidth = Console::WindowWidth;
      saveCursorVisible = Console::CursorVisible;
      
      //
      Console::Clear();
      Console::WriteLine( m1 );
      Console::ReadKey( true );
      
      // Set the smallest possible window size before setting the buffer
 size.
      Console::SetWindowSize( 1, 1 );
      Console::SetBufferSize( 80, 80 );
      Console::SetWindowSize( 40, 20 );
      
      // Create grid lines to fit the buffer. (The buffer width is 80,
 but
      // this same technique could be used with an arbitrary buffer
 width.)
      for ( y = 0; y < Console::BufferWidth / g1->Length;
 y++ )
      {
         sbG1->Append( g1 );
         sbG2->Append( g2 );

      }
      sbG1->Append( g1, 0, Console::BufferWidth % g1->Length );
      sbG2->Append( g2, 0, Console::BufferWidth % g2->Length );
      grid1 = sbG1->ToString();
      grid2 = sbG2->ToString();
      Console::CursorVisible = false;
      Console::Clear();
      for ( y = 0; y < Console::BufferHeight - 1; y++ )
      {
         if ( y % 3 == 0 )
                  Console::Write( grid1 );
         else
                  Console::Write( grid2 );

      }
      Console::SetWindowPosition( 0, 0 );
      do
      {
         cki = Console::ReadKey( true );
         switch ( cki.Key )
         {
            case ConsoleKey::LeftArrow:
               if ( Console::WindowLeft > 0 )
                              Console::SetWindowPosition( Console::WindowLeft - 1,
 Console::WindowTop );
               break;

            case ConsoleKey::UpArrow:
               if ( Console::WindowTop > 0 )
                              Console::SetWindowPosition( Console::WindowLeft, Console::WindowTop
 - 1 );
               break;

            case ConsoleKey::RightArrow:
               if ( Console::WindowLeft < (Console::BufferWidth
 - Console::WindowWidth) )
                              Console::SetWindowPosition( Console::WindowLeft + 1,
 Console::WindowTop );
               break;

            case ConsoleKey::DownArrow:
               if ( Console::WindowTop < (Console::BufferHeight
 - Console::WindowHeight) )
                              Console::SetWindowPosition( Console::WindowLeft, Console::WindowTop
 + 1 );
               break;
         }
      }
      while ( cki.Key != ConsoleKey::Escape );
   }
   catch ( IOException^ e ) 
   {
      Console::WriteLine( e->Message );
   }
   finally
   {
      Console::Clear();
      Console::SetWindowSize( 1, 1 );
      Console::SetBufferSize( saveBufferWidth, saveBufferHeight );
      Console::SetWindowSize( saveWindowWidth, saveWindowHeight );
      Console::CursorVisible = saveCursorVisible;
   }

} // end Main


/*
This example produces results similar to the following:

1) Press the cursor keys to move the console window.
2) Press any key to begin. When you're finished...
3) Press the Escape key to quit.

...

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

*/
// This example demonstrates the Console.WindowLeft and
//                               Console.WindowTop properties.
import System.*;
import System.Text.*;
import System.IO.*;
//
class Sample
{
    public static int saveBufferWidth;
    public static int saveBufferHeight;
    public static int saveWindowHeight;
    public static int saveWindowWidth;
    public static boolean saveCursorVisible;
    //
    public static void main(String[]
 args)
    {
        String m1 = "1) Press the cursor keys to move the console window.\n"
            + "2) Press any key to begin. When you're finished...\n"
            + "3) Press the Escape key to quit.";
        String g1 = "+----";
        String g2 = "|    ";
        String grid1;
        String grid2;
        StringBuilder sbG1 = new StringBuilder();
        StringBuilder sbG2 = new StringBuilder();
        ConsoleKeyInfo cki;
        int y;
        //
        try {
            saveBufferWidth = Console.get_BufferWidth();
            saveBufferHeight = Console.get_BufferHeight();
            saveWindowHeight = Console.get_WindowHeight();
            saveWindowWidth = Console.get_WindowWidth();
            saveCursorVisible = Console.get_CursorVisible();
            //
            Console.Clear();
            Console.WriteLine(m1);
            Console.ReadKey(true);

            // Set the smallest possible window size before setting
 the buffer
            // size.
            Console.SetWindowSize(1, 1);
            Console.SetBufferSize(80, 80);
            Console.SetWindowSize(40, 20);

            // Create grid lines to fit the buffer. (The buffer width is 80,
 but
            // this same technique could be used with an arbitrary buffer
 width.)
            for (y = 0; y < Console.get_BufferWidth() / g1.get_Length();
 y++) {
                sbG1.Append(g1);
                sbG2.Append(g2);
            }

            sbG1.Append(g1, 0, Console.get_BufferWidth() % g1.get_Length());
            sbG2.Append(g2, 0, Console.get_BufferWidth() % g2.get_Length());
            grid1 = sbG1.ToString();
            grid2 = sbG2.ToString();

            Console.set_CursorVisible(false);
            Console.Clear();
            for (y = 0; y < Console.get_BufferHeight() - 1;
 y++) {
                if (y % 3 == 0) {
                    Console.Write(grid1);
                }
                else {
                    Console.Write(grid2);
                }
            }
            Console.SetWindowPosition(0, 0);
            do {
                cki = Console.ReadKey(true);
                switch (cki.get_Key()) {
                    case ConsoleKey.LeftArrow :
                        if (Console.get_WindowLeft() > 0) {
                            Console.SetWindowPosition(Console.get_WindowLeft()-1
,
                                Console.get_WindowTop());
                        }
                        break;
                    case ConsoleKey.UpArrow :
                        if (Console.get_WindowTop() > 0) {
                            Console.SetWindowPosition(Console.get_WindowLeft(),
                                Console.get_WindowTop() - 1);
                        }
                        break;
                    case ConsoleKey.RightArrow :
                        if (Console.get_WindowLeft() < Console.get_BufferWidth()
                            - Console.get_WindowWidth()) {
                            Console.SetWindowPosition(Console.get_WindowLeft()+1
,
                                Console.get_WindowTop());
                        }
                        break;
                    case ConsoleKey.DownArrow :
                        if (Console.get_WindowTop() < Console.get_BufferHeight()
                            - Console.get_WindowHeight()) {
                            Console.SetWindowPosition(Console.get_WindowLeft(),
                                Console.get_WindowTop() + 1);
                        }
                        break;
                }
            } while (!(cki.get_Key().Equals(ConsoleKey.Escape)));
 // end do-while
        } // end try
        catch (IOException e) {
            Console.WriteLine(e.get_Message());
        }
        finally {
            Console.Clear();
            Console.SetWindowSize(1, 1);
            Console.SetBufferSize(saveBufferWidth, saveBufferHeight);
            Console.SetWindowSize(saveWindowWidth, saveWindowHeight);
            Console.set_CursorVisible(saveCursorVisible);
        }
    } //end main
} //end Sample
/*
This example produces results similar to the following:

1) Press the cursor keys to move the console window.
2) Press any key to begin. When you're finished...
3) Press the Escape key to quit.

...

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

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



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

辞書ショートカット

すべての辞書の索引

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

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

   

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



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

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

©2024 GRAS Group, Inc.RSS