Using Microsoft.VisualBasic Namespace in C#. Input Box.
Sometimes it’s very useful to get quickly an input from the user in your application. If you just want to prompt the user to enter a single string, it would be absurdly to dedicate a form for such a simple task. C# itself does not offer such a pleasant convenience as InputBox. It is buried in the depths of Microsoft.VisualBasic name space. You have to add this name space to your references in order to use the InputBox.
The function InputBox looks like:
public static string InputBox (
string Prompt,
[OptionalAttribute] string Title,
[OptionalAttribute] string DefaultResponse,
[OptionalAttribute] int XPos,
[OptionalAttribute] int YPos)
There is a possibility to seperate the line of Promp string. For this purpose just use carriage return character (Chr(13)), a line feed character (Chr(10)), or a carriage return/line feed combination (Chr(13) & Chr(10)).
How the InputBox works is demonstrated in the example bellow:
string promptString = "Please enter something here";
String titleString = "Input Required";
String defaultResponse = "something";
int xPosition = 80;
int yPosition = 80;
string inputString =
Microsoft.VisualBasic.Interaction.InputBox(
promptString,
titleString,
defaultResponse,
xPosition,
yPosition
);
if(inputString != "") {
MessageBox.Show("You entered: " + inputString);
} else {
MessageBox.Show("You entered nothing or you just closed InputBox");
}
Please pay attention, that if you just close the InputBox your inputString will be empty.
