How C # pops up the input box

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.