我有一个点击事件,如下所示。单击时,消息框将按预期显示...但是,单击"确定"在Messagebox中,Messagebox不会关闭。点击" 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));
}
答案 0 :(得分:0)
问题是因为在后台运行的计时器检查任务栏是否调整大小。有一次,我停止了计时器...... Messagebox工作正常