picture

Using Microsoft.VisualBasic Namespace in C#. Input Box.

Sometimes it’s very useful to get quickly an input from the user in your application. If you just want to prompt the user to enter a single string, it would be absurdly to dedicate a form for such a simple task. C# itself does not offer such a pleasant convenience as InputBox. It is buried in the depths of Microsoft.VisualBasic name space. You have to add this name space to your references in order to use the InputBox.

The function InputBox looks like:

public static string InputBox (
	       string Prompt,
  	       [OptionalAttribute] string Title,
 	       [OptionalAttribute] string DefaultResponse,
	       [OptionalAttribute] int XPos,
               [OptionalAttribute] int YPos)

There is a possibility to seperate the line of Promp string. For this purpose just use carriage return character (Chr(13)), a line feed character (Chr(10)), or a carriage return/line feed combination (Chr(13) & Chr(10)).

How the InputBox works is demonstrated in the example bellow:

string promptString = "Please enter something here";

String titleString = "Input Required";

String defaultResponse = "something";

int xPosition = 80;

int yPosition = 80;

string inputString =

Microsoft.VisualBasic.Interaction.InputBox(

promptString,

titleString,

defaultResponse,

xPosition,

yPosition

);

if(inputString != "") {

MessageBox.Show("You entered: " + inputString);

} else {

MessageBox.Show("You entered nothing or you just closed InputBox");

}

Please pay attention, that if you just close the InputBox your inputString will be empty.


Comments to the Post

  • Howdy there,Excellent blogging dude! i am just Fed up with using RSS feeds and do you use twitter?so i can follow you there:D.
    PS:Do you thought putting video to your blog posts to keep the readers more entertained?I think it works.Yours, Manuela Cassada

    author: Manuela Cassada | May 18th, 2010 at 4:30 pm
  • Hi – really good website you have made. I enjoyed reading this posting. I did want to write a comment to tell you that the design of this site is very aesthetically sweet. I used to be a graphic designer, now I am a copy editor in chief. I have always enjoyed working with information processing systems and am attempting to learn computer code in my free time.

    author: Silver Bullion Bars | July 3rd, 2010 at 10:09 pm
  • I was scanning something else about this on another blog. Interesting. Your linear perspective on it is diametrically opposed to what I read before. I am still reflecting over the various points of view, but I’m tipped heavily toward yours. And irrespective, that’s what is so good about modern democracy and the marketplace of thoughts online.

    author: 1-Oz Silver Rounds | July 4th, 2010 at 4:11 pm
  • Hi – very great website you have created. I enjoyed reading this posting. I did want to write a remark to tell you that the design of this site is very aesthetically delightful. I used to be a graphic designer, now I am a copy editor in chief. I have always enjoyed playing with computers and am attempting to learn computer code in my free time.

    author: Engelhard Silver Bars | July 4th, 2010 at 5:00 pm
  • Hi all, im really happy :) i just got my new IPhone 4G for FREE lol!. I didn’t think it would work but it pulled through. I followed the steps on http://freeiphone4g4u.blogspot.com and i just thought ide share it!

    author: Fernando Koterba | July 29th, 2010 at 2:05 am

Leave a Reply

For spam detection purposes, please copy the number 7492 to the field below: