C# MessageBox Tutorial: Create Dialog Boxes

In C#, you can create dialog boxes using the MessageBox class. You can display the dialog box using the MessageBox.Show() method and pass in relevant parameters to set the title, message content, button style, etc.

Here is a simple example code demonstrating how to create a basic dialog box in C#.

using System;
using System.Windows.Forms;

class Program
{
    static void Main()
    {
        // 显示一个简单的消息框
        MessageBox.Show("Hello, World!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
}

In the above code, the MessageBox.Show() method takes four parameters.

  1. Message: “Greetings, Earth!”
  2. Title: “Tips”
  3. Button style: MessageBoxButtons.OK represents only one “OK” button.
  4. Icon style: MessageBoxIcon.Information represents displaying an information icon.

By setting different parameters, you can customize the style of message boxes. For more information on how to use and set parameters in the MessageBox class, please refer to the MSDN documentation.

bannerAds