Sign in to follow this  

Does C# have a equivelant VB.NET InputBox()?

Recommended Posts

.NET doesn't provide a InputBox(), but you could make one yourself:

public static InputBoxResult Show(string prompt, string title, string defaultResponse,
InputBoxValidatingHandler validator, int xpos, int ypos) {
using (InputBox form = new InputBox()) {
form.labelPrompt.Text = prompt;
form.Text = title;
form.textBoxText.Text = defaultResponse;
if (xpos >= 0 && ypos >= 0) {
form.StartPosition = FormStartPosition.Manual;
form.Left = xpos;
form.Top = ypos;
form.Validator = validator;

DialogResult result = form.ShowDialog();

InputBoxResult retval = new InputBoxResult();
if (result == DialogResult.OK) {
retval.Text = form.textBoxText.Text;
retval.OK = true;
return retval;

public static InputBoxResult Show(string prompt, string title, string defaultText,
InputBoxValidatingHandler validator) {
return Show(prompt, title, defaultText, validator, -1, -1);


private  void buttonTest_Click(object  sender, System.EventArgs e) {
InputBoxResult result = InputBox.Show("Test prompt:", "Some title", "Default text", null);
if (result.OK) {
textBox1.Text = result.Text;

I found that one using the good ol' Google. Hope it helps!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this