Although seem lie, in the C# language not exist a dialog box for ask a data. If you don’t want create your own dialog box and don’t need personalize it, you can use the sentence Inputbox that you can find in Microsoft.VisualBasic assembly.
This sentence show a modal dialog with a label, text box, a button accept and other button for cancel.
The definition of sentence InputBox is as follow:
public static string InputBox(
string Prompt,
string Title,
string DefaultResponse,
int XPos,
int YPos)
- Prompt: Dialog message
- Title: Optional. Dialog title.
- DefaultResponse: Optional. answer by default.
- xPos: Optional. Coordinate X, centered by default.
- yPos: Optional. Coordinate Y, centered by default.
Steps for insert an InputBox in C#:
1. Insert a reference to Microsoft.VisualBasic assembly:
2. Insert the sentence:
private void btnClickInputBox_Click(object sender, EventArgs e)
{
string texto = Microsoft.VisualBasic.Interaction.InputBox(
"Texto de la pregunta",
"Titulo del diálogo",
"Respuesta por defecto");
}
Note: if the user cancels the dialog then the statement returns an empty string
Result: