What is the C# version of VB.net's InputDialog?


What is the C# version of VB.net's InputBox?

12/9/2018 7:53:12 PM

Accepted Answer

Add a reference to Microsoft.VisualBasic, InputBox is in the Microsoft.VisualBasic.Interaction namespace:

using Microsoft.VisualBasic;
string input = Interaction.InputBox("Prompt", "Title", "Default", -1, -1);
3/23/2019 9:49:05 PM

To sum it up:

  • There is none in C#.
  • You can use the dialog from Visual Basic by adding a reference to Microsoft.VisualBasic:

    1. In Solution Explorer right-click on the References folder.
    2. Select Add Reference...
    3. In the .NET tab (in newer Visual Studio verions - Assembly tab) - select Microsoft.VisualBasic
    4. Click on OK

Then you can use the previously mentioned code:

string input = Microsoft.VisualBasic.Interaction.InputBox("Prompt", "Title", "Default", 0, 0);

That said, I suggest that you consider the need of an input box in the first place. Dialogs are not always the best way to do things and sometimes they do more harm than good - but that depends on the particular situation.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow