The implementation method of calling InputBox class in VB in C # _c# tutorial

Source: Internet
Author: User

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
}

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.