xtd 0.2.0
Loading...
Searching...
No Matches

◆ set_window_size()

static void xtd::console::set_window_size ( int32  width,
int32  height 
)
static

Sets the height and width of the console window to the specified values.

Parameters
widthThe width of the console window measured in columns.
heightThe height of the console window measured in rows.
Exceptions
xtd::argument_out_of_range_exceptionwidth or height is less than or equal to zero.
-or-
width plus WindowLeft or height plus WindowTop is greater than or equal to xtd::int16_object.max_value.
-or-
width or height is greater than the largest possible window width or height for the current screen resolution and console font.
Examples
This example demonstrates the SetWindowSize method, and the WindowWidth and WindowHeight properties. You must run the example to see the full effect of changing the console window size. The example reports the dimensions of a console window set to 85 columns and 43 rows, then waits for a key press. When any key is pressed, the dimensions of the console window are halved, the new dimensions are reported, and the example waits for another key press. Finally, when any key is pressed the console window is restored to its original dimensions and the example terminates.
#include <xtd/console>
using namespace xtd;
auto main() -> int {
auto orig_width = 0, width = 0;
auto orig_height = 0, height = 0;
auto m1 = "The current window width is {0}, and the current window height is {1}.";
auto m2 = "The new window width is {0}, and the new window height is {1}.";
auto m4 = " (Press any key to continue...)";
//
// Step 1: Get the current window dimensions.
//
orig_width = console::window_width();
orig_height = console::window_height();
//
// Step 2: Cut the window to 1/4 its original size.
//
width = orig_width / 2;
height = orig_height / 2;
console::set_window_size(width, height);
//
// Step 3: Restore the window to its original size.
//
console::set_window_size(orig_width, orig_height);
// This code produces the following output :
//
// The current window width is 100, and the current window height is 60.
// (Press any key to continue...)
// The new window width is 50, and the new window height is 30.
// (Press any key to continue...)
// The current window width is 100, and the current window height is 60.
static int32 window_height()
Gets the height of the console window area.
static void set_window_size(int32 width, int32 height)
Sets the height and width of the console window to the specified values.
static console_key_info read_key()
Obtains the next character or function key pressed by the user. The pressed key is displayed in the c...
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
static int32 window_width()
Gets the width of the console window area.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10