tags:

views:

4433

answers:

9

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

A: 

There is no such thing: I recommend to write it for yourself and use it whenever you need.

MADMap
+1  A: 

You mean InputBox? Just look in the Microsoft.VisualBasic namespace.

C# and VB.Net share a common library. If one language can use it, so can the other.

Joel Coehoorn
+3  A: 

There isn't one. If you really wanted to use the VB InputBox in C# you can. Just add reference to Microsoft.VisualBasic.dll and you'll find it there.

But I would suggest to not use it. It is ugly and outdated IMO.

Ryan Farley
I think you are being too kind. It's far more ugly and outdated than that!
BlackWasp
A: 

AFAIK there isn't one and good thing too.

Why would you want it? Write a PROPER dialog.

+7  A: 

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

string input = Microsoft.VisualBasic.Interaction.InputBox("Prompt", "Title", "Default", 0, 0);
Ozgur Ozcitak
Bah... fastest gun in the west haha.... anyway I looked up the actual signature in Object Browser and prompt comes before title, so its "Prompt" first and then "Title".. the last 2 number is X/Y coordinates to display the inputbox
chakrit
+1  A: 

Add reference to Microsoft.VisualBasic and use this function:

string response =  Microsoft.VisualBasic.Interaction.InputBox("What's 1+1?", "Title", "2", 0, 0);

The last 2 number is an X/Y position to display the input dialog.

chakrit
+9  A: 

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 select Microsoft.VisualBasic
    4. Click on OK

Then you can use the previously mentioned code:

string input = Microsoft.VisualBasic.Interaction.InputBox("Title", "Prompt", "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.

Tomas Sedovic
You can use the dialog from C# by adding that reference, too.
Joel Coehoorn
Input boxes are a godsend for testing ui...
Mladen Mihajlovic
Yeah, they are. But it seems to me that in most cases they're bad in the shipping code.
Tomas Sedovic
+1  A: 

you need to add the microsoft.visualbasic dll in your references first.

+1  A: 

You can use the following Sample Input Dialog Templet found here: link text

Oronno