0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

メッセージボックス

Last updated at Posted at 2024-01-29
using System;
using System.Windows.Forms;

class Program
{
    static void Main()
    {
        ShowMessageBox("Hello, World!");
    }

    static void ShowMessageBox(string message)
    {
        // 既に同じメッセージが表示されていないか確認
        if (!IsMessageBoxShowing(message))
        {
            MessageBox.Show(message);
        }
    }

    static bool IsMessageBoxShowing(string message)
    {
        // メッセージボックスが表示されているかどうかを確認するロジックを実装
        foreach (Form form in Application.OpenForms)
        {
            if (form is MessageBox && ((MessageBox)form).Text == message)
            {
                return true;
            }
        }
        return false;
    }
}
using System;
using System.Linq;
using System.Windows;

namespace WpfMessageBoxExample
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void ShowUniqueMessageBox(string message)
        {
            // 既に同じメッセージが表示されていないか確認
            if (!IsMessageBoxShowing(message))
            {
                MessageBox.Show(message);
            }
        }

        private bool IsMessageBoxShowing(string message)
        {
            // 開いているすべてのウィンドウを取得し、同じメッセージを持つウィンドウが存在するか確認
            return Application.Current.Windows.OfType<Window>()
                .Any(window => window is MessageBox && ((MessageBox)window).Title == message);
        }

        private void ShowMessageBoxButton_Click(object sender, RoutedEventArgs e)
        {
            ShowUniqueMessageBox("Hello, World!");
        }
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?