Steps to Implement inputbox on Button Click in C#.Net
1>Drag a Button on Form
2>Right click on project in Solution Explorer and Click on Add Reference
3>Select Microsoft.VisualBasic
4>Click Ok
Then come to code and write the below code:
using Microsoft.VisualBasic;
private void button1_Click(object sender, EventArgs e)
{
//string myValue = Interaction.InputBox("Enter Name","Input Box","Name Here", 100, 100);
//MessageBox.Show(myValue);
//or
string message, title, defaultValue;
string myValue;
// Set prompt.
message = "Enter a value between 1 and 3";
// Set title.
title = "InputBox Demo";
// Set default value.
defaultValue = "1";//Display message, title, and default value.
myValue =Interaction.InputBox(message, title, defaultValue,100,100);// If user has clicked Cancel, set myValue to defaultValue
if (myValue == "")
{
myValue = defaultValue;
MessageBox.Show(myValue);
}
else
{
//MessageBox.Show(myValue);
}
}
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.
mark courtPosted Mar 31, 2016, 9:17 PM
To fix the 'Interaction' you need to ADD a Reference. Right click Reference > Add reference > Click on .NET and choose Ms Visual basic. Then you can debug this code which works in c#. YOUR WELCOME!
Vipin SaxenaPosted Jun 30, 2015, 3:05 AM
The type or namespace name 'Interaction' does not exist in the namespace 'Microsoft.VisualBasic' (are you missing an assembly reference?)
M MeenakshiPosted Apr 9, 2013, 3:27 PM
the above code for inputbox is not working at my site. it is showing an error to the "interaction". it is showing me an error as "the name 'interaction' does not exist in the current context". now what else i have to write in my project-code to make it execute successfully...??? please suggest me as early as possible..
rohol aminPosted Nov 14, 2012, 11:53 AM
Thank for your source code.
Jilani ShiakhPosted Jul 25, 2010, 2:08 AM
Dear Sushant, this is very nice implementation.