Monday, August 16, 2010

InputBox in C#

Many programmers who come from Visual Basic maybe miss the good old InputBox. For those and others who seek a an easy possibility to let the user input data, I today show, how to use the InputBox of Visual Basic.
This calls a modal window, an input box, in which the user can can input data. First a reference to the Visual Basic library is required, which can be added via Project - Add Reference - (Tab .Net) - Microsoft.VisualBasic.
Now the input box can be used via Microsoft.VisualBasic.Interaction.InputBox() in the project.
There are 5 parameters of which only the first one is necessary.
They are:

  1. Text of the input box
  2. Title 
  3. Default input
  4. x coordinate
  5. y coordinate


The function returns the input as a string:

string Response = Microsoft.VisualBasic.Interaction.InputBox("Beispieldialogtext""Titel""Vorgabeantwort", 0, 0);

Above code creates the following InputBox:

No comments:

Post a Comment