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

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

Console.SetWindowSize メソッド

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

コンソール ウィンドウの高さと幅を指定された値に設定します

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

例外例外
例外種類条件

ArgumentOutOfRangeException

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

または

width と WindowLeft を足した値または height と WindowTop を足した値が Int16.MaxValue 以上です。

または

width または height に、現在の画面解像度コンソール フォント利用可能最大ウィンドウ幅または最大ウィンドウ高さを超える値が指定されています。

SecurityException

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

IOException

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

使用例使用例

SetWindowSize メソッド、WindowWidth プロパティ、および WindowHeight プロパティ使用例次に示します。この例を実行すると、コンソール ウィンドウサイズ実際にどのように変化するのかを確認できます

この例は、まず、コンソール ウィンドウの元のサイズ (85 列× 43 行) を表示しユーザーからのキー入力待ちますなんらかのキー押されると、コンソール ウィンドウサイズ半分縮小した後、新しサイズ表示し、再び、ユーザーからのキー入力待ちます最後になんらかのキー押されると、コンソール ウィンドウを元のサイズ戻して終了します

' This example demonstrates the Console.SetWindowSize method,
'                           the Console.WindowWidth property, 
'                       and the Console.WindowHeight property.
Imports System

Class Sample
   Public Shared Sub Main()
      Dim origWidth, width As Integer
      Dim origHeight, height As Integer
      Dim m1 As String =
 "The current window width is {0}, and the " &
 _
                         "current window height is {1}."
      Dim m2 As String =
 "The new window width is {0}, and the new " &
 _
                         "window height is {1}."
      Dim m4 As String =
 "  (Press any key to continue...)"
      '
      ' Step 1: Get the current window dimensions.
      '
      origWidth = Console.WindowWidth
      origHeight = Console.WindowHeight
      Console.WriteLine(m1, Console.WindowWidth, Console.WindowHeight)
      Console.WriteLine(m4)
      Console.ReadKey(True)
      '
      ' Step 2: Cut the window to 1/4 its original size.
      '
      width = origWidth / 2
      height = origHeight / 2
      Console.SetWindowSize(width, height)
      Console.WriteLine(m2, Console.WindowWidth, Console.WindowHeight)
      Console.WriteLine(m4)
      Console.ReadKey(True)
      '
      ' Step 3: Restore the window to its original size.
      '
      Console.SetWindowSize(origWidth, origHeight)
      Console.WriteLine(m1, Console.WindowWidth, Console.WindowHeight)
   End Sub 'Main
End Class 'Sample
'
'This example produces the following results:
'
'The current window width is 85, and the current window height is 43.
'  (Press any key to continue...)
'The new window width is 42, and the new window height is 21.
'  (Press any key to continue...)
'The current window width is 85, and the current window height is 43.
'
'
// This example demonstrates the Console.SetWindowSize method,
//                           the Console.WindowWidth property, 
//                       and the Console.WindowHeight property.
using System;

class Sample 
{
    public static void Main()
 
    {
    int origWidth, width;  
    int origHeight, height;
    string m1 = "The current window width is {0}, and the
 " +
                "current window height is {1}.";
    string m2 = "The new window width
 is {0}, and the new " +
                "window height is {1}.";
    string m4 = "  (Press any key to continue...)";
//
// Step 1: Get the current window dimensions.
//
    origWidth  = Console.WindowWidth;
    origHeight = Console.WindowHeight;
    Console.WriteLine(m1, Console.WindowWidth,
                          Console.WindowHeight);
    Console.WriteLine(m4);
    Console.ReadKey(true); 
//
// Step 2: Cut the window to 1/4 its original size.
//
    width  = origWidth/2;
    height = origHeight/2;
    Console.SetWindowSize(width, height);
    Console.WriteLine(m2, Console.WindowWidth,
                          Console.WindowHeight);
    Console.WriteLine(m4);
    Console.ReadKey(true); 
//
// Step 3: Restore the window to its original size.
//
    Console.SetWindowSize(origWidth, origHeight);
    Console.WriteLine(m1, Console.WindowWidth,
                          Console.WindowHeight);
    }
}
/*
This example produces the following results:

The current window width is 85, and the current window height is 43.
  (Press any key to continue...)
The new window width is 42, and the new window
 height is 21.
  (Press any key to continue...)
The current window width is 85, and the current window height is 43.

*/
// This example demonstrates the Console.SetWindowSize method,
//                           the Console.WindowWidth property, 
//                       and the Console.WindowHeight property.
using namespace System;
int main()
{
   int origWidth;
   int width;
   int origHeight;
   int height;
   String^ m1 = "The current window width is {0}, and the "
   "current window height is {1}.";
   String^ m2 = "The new window width is {0}, and the new
 "
   "window height is {1}.";
   String^ m4 = "  (Press any key to continue...)";
   
   //
   // Step 1: Get the current window dimensions.
   //
   origWidth = Console::WindowWidth;
   origHeight = Console::WindowHeight;
   Console::WriteLine( m1, Console::WindowWidth, Console::WindowHeight );
   Console::WriteLine( m4 );
   Console::ReadKey( true );
   
   //
   // Step 2: Cut the window to 1/4 its original size.
   //
   width = origWidth / 2;
   height = origHeight / 2;
   Console::SetWindowSize( width, height );
   Console::WriteLine( m2, Console::WindowWidth, Console::WindowHeight );
   Console::WriteLine( m4 );
   Console::ReadKey( true );
   
   //
   // Step 3: Restore the window to its original size.
   //
   Console::SetWindowSize( origWidth, origHeight );
   Console::WriteLine( m1, Console::WindowWidth, Console::WindowHeight );
}

/*
This example produces the following results:

The current window width is 85, and the current window height is 43.
  (Press any key to continue...)
The new window width is 42, and the new window
 height is 21.
  (Press any key to continue...)
The current window width is 85, and the current window height is 43.

*/
// This example demonstrates the Console.SetWindowSize method,
//                           the Console.WindowWidth property, 
//                       and the Console.WindowHeight property.
import System.*;

class Sample
{
    public static void main(String[]
 args)
    {
        int origWidth, width;
        int origHeight, height;
        String m1 = "The current window width is {0}, and the " 
            + "current window height is {1}.";
        String m2 = "The new window width is {0}, and the
 new " 
            + "window height is {1}.";
        String m4 = "  (Press any key to continue...)";
        //
        // Step 1: Get the current window dimensions.
        //
        origWidth = Console.get_WindowWidth();
        origHeight = Console.get_WindowHeight();
        Console.WriteLine(m1, System.Convert.ToString(Console.get_WindowWidth())
,
            System.Convert.ToString(Console.get_WindowHeight()));
        Console.WriteLine(m4);
        Console.ReadKey(true);
        //
        // Step 2: Cut the window to 1/4 its original size.
        //
        width = origWidth / 2;
        height = origHeight / 2;
        Console.SetWindowSize(width, height);
        Console.WriteLine(System.Convert.ToString(m2), 
            System.Convert.ToString(Console.get_WindowWidth()),
            System.Convert.ToString(Console.get_WindowHeight()));
        Console.WriteLine(m4);
        Console.ReadKey(true);
        //
        // Step 3: Restore the window to its original size.
        //
        Console.SetWindowSize(origWidth, origHeight);
        Console.WriteLine(System.Convert.ToString(m1),
            System.Convert.ToString(Console.get_WindowWidth()), 
            System.Convert.ToString(Console.get_WindowHeight()));
    } //main
} //Sample
/*
This example produces the following results:

The current window width is 85, and the current window height is 43.
  (Press any key to continue...)
The new window width is 42, and the new window
 height is 21.
  (Press any key to continue...)
The current window width is 85, and the current window height is 43.

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


このページでは「.NET Framework クラス ライブラリ リファレンス」からConsole.SetWindowSize メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からConsole.SetWindowSize メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からConsole.SetWindowSize メソッド を検索

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

辞書ショートカット

すべての辞書の索引

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

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

   

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



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

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

©2025 GRAS Group, Inc.RSS