Messagebox Click 不工作 C#

Messagebox Click not working C#

我有一个如下所示的点击事件。单击时,消息框按预期显示...但是,在消息框中单击 "OK" 时,消息框不会关闭。单击消息框 window 中的 "X"(关闭)按钮,它会按预期关闭。

观察:如果将 MessageBox 放置在 "For Loop" 之前,则可以正常工作 运行。

 private void Icon_Clicked(object sender, EventArgs e, Panel iconPanel)
  {
        if (iconPanel.Name == "Logout")
          {
             MessageBox.Show("Logout");
          }
  }

  public static List<String> ProjectDomains = new List<String>();
  ProjectDomains.Add("Logout");
  ProjectDomains.Add("Designers");
  ProjectDomains.Add("Animators");

foreach (var domain in ProjectDomains)
  {
        Panel iconPanel = new Panel();
        PictureBox iconPic = new PictureBox();
        Label iconlabel = new Label();

        iconPanel.Name = domain;
        iconPic.Name = domain;
        iconlabel.Name = domain;

        iconPanel.MouseEnter += new EventHandler((sender, e) => Icon_MouseEnter(sender, e, iconPanel));
        iconPanel.MouseLeave += new EventHandler((sender, e) => Icon_MouseLeave(sender, e, iconPanel));
        iconPic.MouseEnter += new EventHandler((sender, e) => Icon_MouseEnter(sender, e, iconPanel));
        iconPic.MouseLeave += new EventHandler((sender, e) => Icon_MouseLeave(sender, e, iconPanel));
        iconlabel.MouseEnter += new EventHandler((sender, e) => Icon_MouseEnter(sender, e, iconPanel));
        iconlabel.MouseLeave += new EventHandler((sender, e) => Icon_MouseLeave(sender, e, iconPanel));

        iconPanel.Click += new EventHandler((sender, e) => Icon_Clicked(sender, e, iconPanel));
        iconPic.Click += new EventHandler((sender, e) => Icon_Clicked(sender, e, iconPanel));
        iconlabel.Click += new EventHandler((sender, e) => Icon_Clicked(sender, e, iconPanel));
  }

问题是因为 运行 在后台检查任务栏大小的计时器。有一次,我停止了计时器..Messagebox 正常工作