C# のポップアップメッセージ

Muhammad Maisam Abbas 2021年8月10日 2021年5月9日
C# のポップアップメッセージ

このチュートリアルでは、C# でポップアップメッセージウィンドウを表示する方法について説明します。

C# の MessageBox クラスでポップアップメッセージを表示する

ボタンがあり、ボタンがクリックされたときにポップアップメッセージを表示したい場合は、C# で MessageBox クラスを使用できます。MessageBox.Show() メソッドは、C# で画面にメッセージウィンドウを表示します。MessageBox.Show() メソッドは、入力パラメーターとして文字列形式のメッセージを受け取り、それをユーザーに表示します。次のコード例は、C# の MessageBox.Show() メソッドでボタンのクリックに応答してメッセージを表示する簡単なポップアップメッセージウィンドウを作成する方法を示しています。

using System;
using System.Windows.Forms;

namespace popup
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string text = "This is some Text that I wanted to show";
            MessageBox.Show(text);
        }
    }
}

出力:

C# ポップアップメッセージ

上記のコードでは、C# の MessageBox.Show() 関数を使用してユーザーが button1 をクリックするたびに表示されるポップアップメッセージウィンドウを作成しました。

Muhammad Maisam Abbas avatar Muhammad Maisam Abbas avatar

Maisam is a highly skilled and motivated Data Scientist. He has over 4 years of experience with Python programming language. He loves solving complex problems and sharing his results on the internet.

LinkedIn

関連記事 - Csharp GUI