Console.WindowWidth プロパティ

定義

コンソール ウィンドウの幅を取得または設定します。

public:
 static property int WindowWidth { int get(); void set(int value); };
public static int WindowWidth { [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] get; [System.Runtime.Versioning.SupportedOSPlatform("windows")] set; }
public static int WindowWidth { [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] [System.Runtime.Versioning.UnsupportedOSPlatform("android")] [System.Runtime.Versioning.UnsupportedOSPlatform("ios")] [System.Runtime.Versioning.UnsupportedOSPlatform("tvos")] get; [System.Runtime.Versioning.SupportedOSPlatform("windows")] set; }
[System.Runtime.Versioning.UnsupportedOSPlatform("android")]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static int WindowWidth { get; set; }
public static int WindowWidth { get; set; }
[<get: System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
[<set: System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member WindowWidth : int with get, set
[<get: System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
[<set: System.Runtime.Versioning.SupportedOSPlatform("windows")>]
[<get: System.Runtime.Versioning.UnsupportedOSPlatform("android")>]
[<get: System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<get: System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
static member WindowWidth : int with get, set
[<System.Runtime.Versioning.UnsupportedOSPlatform("android")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
static member WindowWidth : int with get, set
static member WindowWidth : int with get, set
Public Shared Property WindowWidth As Integer

プロパティ値

列数で指定されたコンソール ウィンドウの幅。

属性

例外

WindowWidth プロパティの値または WindowHeight プロパティの値が 0 以下です。

または

プロパティの WindowHeight 値とプロパティの WindowTop 値が Int16.MaxValue 以上です。

または

WindowWidth プロパティの値または WindowHeight プロパティの値が、現在の画面の解像度およびコンソールのフォントで利用可能なウィンドウの最大幅か最大の高さを超えています。

読み取りまたは書き込み情報エラー。

セット操作は Windows 以外のオペレーティング システムで呼び出されています。

この例では、 SetWindowSize メソッドと プロパティと WindowHeight プロパティをWindowWidth示します。 コンソール ウィンドウのサイズを変更する効果を確認するには、この例を実行する必要があります。

この例では、85 列と 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.
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.
open System

//
// Step 1: Get the current window dimensions.
//
let origWidth  = Console.WindowWidth
let origHeight = Console.WindowHeight
printfn $"The current window width is {Console.WindowWidth}, and the current window height is {Console.WindowHeight}."
printfn "  (Press any key to continue...)"
Console.ReadKey true |> ignore

//
// Step 2: Cut the window to 1/4 its original size.
//
let width  = origWidth / 2
let height = origHeight / 2
Console.SetWindowSize(width, height)
printfn $"The new window width is {Console.WindowWidth}, and the new window height is {Console.WindowHeight}."
                        
printfn "  (Press any key to continue...)"
Console.ReadKey true |> ignore

//
// Step 3: Restore the window to its original size.
//
Console.SetWindowSize(origWidth, origHeight)
printfn $"The current window width is {Console.WindowWidth}, and the current window height is {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.
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
End Class
'
'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.
'
'

注釈

出力がリダイレクトされたときに プロパティの値をWindowWidth設定しようとすると、 または 例外IOExceptionArgumentOutOfRangeExceptionスローされます。 例外を回避するには、 プロパティが を返す場合にのみ、このプロパティの値をIsOutputRedirectedfalse設定します。

適用対象