Jump to content
  • Advertisement
Sign in to follow this  

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

This topic is 4849 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!