Console.SetWindowSize メソッド
アセンブリ: mscorlib (mscorlib.dll 内)



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. */


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からConsole.SetWindowSize メソッドを検索する場合は、下記のリンクをクリックしてください。

- Console.SetWindowSize メソッドのページへのリンク