Or, one could set a reference to Microsoft.VisualBasic.dll assembly
and call the InputBox method on the Interaction class in the
Microsoft.VisualBasic namespace.
Some don't like the idea of loading Microsoft.VisualBasic.dll, but
it's there to use if one wants (and I assume the OP wanted this, as he
used the name of the method in VB which does the same thing).
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Peter Duniho said:
Andrus wrote:
I need WinForms function which displays promp and asks single field
from user, like
string res = Util.InputBox( "Enter value" );
How to implement this ?
Make a form with a Label instance for the prompt ("Enter value") and a
TextBox instance for the user input, a button for "OK" and optionally a
"Cancel" button. Make sure the buttons are configured for the correct
DialogResult (set their DialogResult property as desired).
Instantiate the form, call ShowDialog() on it, if the return value is
DialogResult.OK, process the Text property of the TextBox instance as
your entered value.
Wrap all of the above in a method that does all of the work and simply
returns the string value obtained from the Text property of the TextBox.
Don't forget to dispose your form instance before returning.
Pete