In C #, when programming Windows Forms applications, you often need to pop up input boxes, enter passwords, enter text, and so on. However, there is no statement in C # that directly pops up the input box, and the MessageBox can only display a message and cannot be entered. We need to call Microsoft.VisualBasic, using VB in the InputBox, to implement the function of the popup input box.
1. Menu bar, select "Project", then select "Add Reference" in the popup menu.
2. Pop up the "Add Reference" window, find the component named Microsoft.VisualBasic, select it and click "OK"
3. Use namespace Microsoft.VisualBasic. Add code: Using Microsoft.VisualBasic;
using Microsoft.VisualBasic;
4. Add a Button1 and textBox1 to the form. We want to implement click Button1, display the content of the input text with TextBox1.
5.
Call InputBox in VB and enter a string of strings. Add code to the button:
string str = interaction.inputbox (" hint info "," title ", " text content ",-1,-1);
Format of Interaction.inputbox: String Interaction. InputBox (String prompt,string title,string defaultresponce,int xpos,int ypose)
6. Reference Code:
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.ComponentModel;4 usingSystem.Data;5 usingSystem.Drawing;6 usingSystem.Linq;7 usingSystem.Text;8 usingSystem.Windows.Forms;9 usingMicrosoft.VisualBasic;Ten One namespaceWindowsFormsApplication1 A { - Public Partial classForm1:form - { the PublicForm1 () - { - InitializeComponent (); - } + - Private voidForm1_Load (Objectsender, EventArgs e) + { A at } - - Private voidButton1_Click (Objectsender, EventArgs e) - { - stringstr = Interaction.inputbox ("Prompt Information","title","text content",-1,-1); - inTextBox1.Text =str; - } to } +}
7, the results show:
How C # pops up the input box