开发者

System.ArgumentException was unhandled when using -= on a event delegate?

I have this code:

public void setPanelHalfHorizontalScreen(Panel p)
        {
            if (p != null)
            {
                p.Width = Screen.PrimaryScreen.Bounds.Width / 2 - 2;
                this.panelsForHalfScreen.Add(p.Name, p);

                // http://stackoverflow.com/questions/2261828/does-an-event-gets-executed-twice-if-callback-was-assigned-t开发者_Go百科wice-to-the-object
                this.form.Resize -= new EventHandler(form_Resize); // error raised on this line: ArgumentException was unhandled
                this.form.Resize += new EventHandler(form_Resize);
            }
        }

        void form_Resize(object sender, EventArgs e)
        {

            foreach (DictionaryEntry p in panelsForHalfScreen)
            {
                this.setPanelHalfHorizontalScreen((Panel)p.Value);
            }
        }

How can I fix it?

EDIT

System.ArgumentException was unhandled when using -= on a event delegate?


are you sure that this line does not throw ArgumentException?

this.panelsForHalfScreen.Add(p.Name, p);

cause Add method throws ArgumentException if key already is in Hashtable

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜