Skip to content

ValueInput Control

Iuga Alexandru edited this page Sep 2, 2018 · 2 revisions

Description

Reads a value from the Console input.

Features

  • Custom label - Displays a label before the user types the value.
  • Custom space amount between label and value
  • Optional default value - Specify a value to be used if the user press Enter without typing anythig (string empty).
  • Custom error message for type conversion - When the input string cannot be converted into the requested type.
  • Generic control - Reads any type of data.
  • Custom label color - Specify the foreground and background colors for the label.

Example

Static method (quick)

string firstName = ValueView<string>.QuickRead("First Name:");

Result:

Instance (more power)

ValueView<string> firstNameInput = new ValueView<string>("First Name:");
firstNameInput.LabelForegroundColor = ConsoleColor.Cyan;

string firstName = firstNameInput.Read();

Result:

With default value

ValueView<int> numberInput = new ValueView<int>("Number:");
numberInput.AcceptDefaultValue = true;
numberInput.DefaultValue = 42;

int number = numberInput.Read();
Clone this wiki locally