Console.SetWindowSize(Int32, Int32) Método
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Define a altura e largura da janela do console com os valores especificados.
public:
static void SetWindowSize(int width, int height);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static void SetWindowSize (int width, int height);
[System.Runtime.Versioning.UnsupportedOSPlatform("android")]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static void SetWindowSize (int width, int height);
public static void SetWindowSize (int width, int height);
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member SetWindowSize : int * int -> unit
[<System.Runtime.Versioning.UnsupportedOSPlatform("android")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
static member SetWindowSize : int * int -> unit
static member SetWindowSize : int * int -> unit
Public Shared Sub SetWindowSize (width As Integer, height As Integer)
Parâmetros
- width
- Int32
A largura da janela do console medida em colunas.
- height
- Int32
A altura da janela do console medida em linhas.
- Atributos
Exceções
width
ou height
é menor ou igual a zero.
- ou -
width
plus WindowLeft ou height
plus WindowTop é maior ou igual a Int16.MaxValue.
- ou -
width
ou height
é maior do que a maior largura ou altura de janela possível da fonte do console e resolução de tela atual.
O usuário não tem permissão para executar essa ação.
Ocorreu um erro de E/S.
O sistema operacional atual não é o Windows.
Exemplos
Este exemplo demonstra o SetWindowSize método e as WindowWidth propriedades e WindowHeight . Você deve executar o exemplo para ver o efeito completo da alteração do tamanho da janela do console.
O exemplo relata as dimensões de uma janela de console definida como 85 colunas e 43 linhas e aguarda uma tecla ser pressionada. Quando qualquer tecla é pressionada, as dimensões da janela do console são reduzidas pela metade, as novas dimensões são relatadas e o exemplo aguarda por outra tecla. Por fim, quando qualquer tecla é pressionada, a janela do console é restaurada para suas dimensões originais e o exemplo é encerrado.
// 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.
'
'