Home >Backend Development >C++ >How to Create a C# Equivalent of VB.NET's InputBox?

How to Create a C# Equivalent of VB.NET's InputBox?

DDD
DDDOriginal
2025-01-03 10:50:44463browse

How to Create a C# Equivalent of VB.NET's InputBox?

C# Equivalent of VB.NET's InputBox

VB.NET's InputBox, used to display a modal pop-up window for user input, has a C# counterpart.

C# Implementation

The C# version of InputBox requires adding a reference to the Microsoft.VisualBasic assembly. Once the reference is added, you can access the InputBox function from the Microsoft.VisualBasic.Interaction namespace. Here is the C# code to achieve the same functionality:

using Microsoft.VisualBasic;

namespace InputBoxExample
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Interaction.InputBox("Enter your name:", "Input Box Example", "John Doe", 100, 100);

            Console.WriteLine($"User entered: {input}");
        }
    }
}

In this example:

  • The first argument ("Enter your name:") is the prompt displayed to the user.
  • The second argument ("Input Box Example") is the title of the pop-up window.
  • The third argument ("John Doe") is the default value pre-populated in the input field.
  • The fourth and fifth arguments (100, 100) are the x and y coordinates specifying the position of the pop-up window on the screen.

Note: The only mandatory argument is the first one, which is the prompt displayed to the user.

The above is the detailed content of How to Create a C# Equivalent of VB.NET's InputBox?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn