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
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
精彩评论