C # does not InputBox this class, but InputBox is also good, so there are two ways to use
One: Indirectly call the InputBox function in VB
1. To add a microsoft.visualbasic reference to a project
2. Add the namespace using Microsoft.VisualBasic to the project;
3. In the future, you can directly use a lot of VB library (cool ah ...) )
For example: Textbox1.text=microsoft.visualbasic.interaction.inputbox ("Prompt text", "dialog box title", "Default value", x coordinate, y coordinate);
The X coordinate above, the y-coordinate can be a value of –1 and-1, indicating the middle position of the screen.
Two: You can also write a InputBox () this function. Dynamically generate a form and TextBox and button, and so on, determine the good location, return the user input string.
public partial class Inputbox:form
{
private InputBox ()
{
InitializeComponent ();
}
Public String GetValue ()
{return
textbox1.text;
}
public static bool (string title,string inputtips,bool ispassword,ref string value)
{
InputBox ib = new Inpu Tbox ();
if (title!= null)
{
ib. Text = title;
}
if (inputtips!= null)
{
ib.label1.Text = inputtips;
}
if (Ispassword)
{
Ib.textBox1.PasswordChar = ' * ';
}
if (ib. ShowDialog () ==dialogresult.ok)
{
value = Ib.getvalue ();
Ib. Dispose ();
return true;
}
else
{
ib. Dispose ();
return false;}}
How to use
String value;
if (inputbox.show ("User input", "Password:", true, ref value)
{
//Enter successful operation
}