Skip to content

TextBox

Tyberious edited this page Aug 31, 2023 · 1 revision

TextBox Control

The TextBox control lets users input text in the console.

Properties

  • Value: Gets or sets the current text value of the text box.
  • X and Y: Specify the position of the text box.
  • MaxLength: Set the maximum length of the input.
  • ForegroundColor and BackgroundColor: Customize colors for the text box.
  • HasFocus: Indicates whether the text box has focus.
  • IsPassword: Indicates whether the input should be masked (for passwords).

Example

TextBox usernameBox = new TextBox
{
    X = 10,
    Y = 15,
    MaxLength = 20,
    ForegroundColor = ConsoleColor.Black,
    BackgroundColor = ConsoleColor.Gray
    //A default value for the textbox can be set by assigning the 'Value' property here before we call the SetFocus() method
};

usernameBox.Render();

// Capture user input
string userInput = usernameBox.SetFocus();

Clone this wiki locally