Console.SetWindowSize(Int32, Int32) Metoda
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Nastaví výšku a šířku okna konzoly na zadané hodnoty.
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)
Parametry
- width
- Int32
Šířka okna konzoly měřená ve sloupcích.
- height
- Int32
Výška okna konzoly měřená v řádcích.
- Atributy
Výjimky
width
nebo height
je menší než nebo rovno nule.
-nebo-
width
plus WindowLeft nebo height
plus WindowTop je větší než nebo rovno Int16.MaxValue.
-nebo-
width
nebo height
je větší než největší možná šířka nebo výška okna pro aktuální rozlišení obrazovky a písmo konzoly.
Uživatel nemá oprávnění k provedení této akce.
Došlo k vstupně-výstupní chybě.
Aktuální operační systém není Windows.
Příklady
Tento příklad ukazuje metodu SetWindowSize a WindowWidth vlastnosti a WindowHeight . Pokud chcete vidět úplný efekt změny velikosti okna konzoly, musíte tento příklad spustit.
Příklad hlásí rozměry okna konzoly nastavené na 85 sloupců a 43 řádků a pak čeká na stisknutí klávesy. Když stisknete některou klávesu, rozměry okna konzoly se sníží na polovinu, nahlásí se nové rozměry a příklad počká na další stisknutí klávesy. Když stisknete libovolnou klávesu, okno konzoly se obnoví do původních rozměrů a příklad se ukončí.
// 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.
'
'