views:

54

answers:

1

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-twice-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 alt text

+1  A: 

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

limpalex
check the image I added
Pentium10
are there any details about the exception? like message or stack trace
limpalex
yeah, form_resize calling -> setPanelHalfHorizontalScreen -> exception occurs
Pentium10
without full source code of this class i can't help.
limpalex