I have a control on a userControl1 on a userControl2 on a userControl3
on a Panel on a Form and sometimes I cannot close my form.
I understand it is a known bug that was already discussed, but I
cannot adjust the following solution to my case:
- In which class do I add the following code? (who is 'this')
- Do I have to do it for both userControl1, userControl2 and
userControl3 or just for userControl1 ?
Any help is wellcomed.
Atara.
--------------------
The code I found:
Subject: Why hasn't this .NET bug been corrected yet?
problem:
when a control within a UserControl has focus and is then disposed,
the top-level form containing that disposed control will fail to close
when the 'X' is clicked or when Close() is called.
solution:
if(panelUserCon trolHost.Contro ls.Count > 0)
{
if(this.ctlActi veUserControl != null)
{
panelUserContro lHost.Controls. Remove(this.ctl ActiveUserContr ol);
this.OnControlR emoved(new
ControlEventArg s(ctlActiveUser Control));
ctlActiveUserCo ntrol.Dispose() ;
ctlActiveUserCo ntrol = null;
}
panelUserContro lHost.Controls. Clear();
}
on a Panel on a Form and sometimes I cannot close my form.
I understand it is a known bug that was already discussed, but I
cannot adjust the following solution to my case:
- In which class do I add the following code? (who is 'this')
- Do I have to do it for both userControl1, userControl2 and
userControl3 or just for userControl1 ?
Any help is wellcomed.
Atara.
--------------------
The code I found:
Subject: Why hasn't this .NET bug been corrected yet?
problem:
when a control within a UserControl has focus and is then disposed,
the top-level form containing that disposed control will fail to close
when the 'X' is clicked or when Close() is called.
solution:
if(panelUserCon trolHost.Contro ls.Count > 0)
{
if(this.ctlActi veUserControl != null)
{
panelUserContro lHost.Controls. Remove(this.ctl ActiveUserContr ol);
this.OnControlR emoved(new
ControlEventArg s(ctlActiveUser Control));
ctlActiveUserCo ntrol.Dispose() ;
ctlActiveUserCo ntrol = null;
}
panelUserContro lHost.Controls. Clear();
}