Can't close form

  • Thread starter Thread starter Andy
  • Start date Start date
A

Andy

Hi,
I have a problem with closing a form, when I'm clicking 'x' button,
the form is still visible.
My form has functionality like TabControl. When I add a new control, all
controls are deleted from the form control collection,
(this.Controls.Clear(); this.Controls.Add( c ) ), but old controls aren't
disposed but added to the queue (Private object on the form of
System.Collection.Queue() class).

After adding the new control, I move focus to this control. Property
ActiveControl of the form is set to null. Where may be a problem?

Regards,
Andy
 
Know bug - if the removed control has the focus, then removing it will keep
the form open. Change the focus to another control before removal.

Laurie Paulin
Perth, Western Australia
 
Hi Andy,

The problem is with tricky control removal. You should call the container's
OnControlRemoved protected method before the control has been removed from
the Controls collection, but a reference to the control is still valid.
 
Hi Dimitry,
Just a little supplement to what you said.
You can call OnControlRemoved before controll removal or after it doesn't
really matter. You have to call OnControlRemoved before disposing the
control, though.

OnControlRemoved has to be called on the ultimate container. If a controls
is placed on a user control, which in turn resides on a form after removing
the controll form's OnControlRemoved has to be called. Otherwise it won't
do.

B\rgds
100

Dmitriy Lapshin said:
Hi Andy,

The problem is with tricky control removal. You should call the container's
OnControlRemoved protected method before the control has been removed from
the Controls collection, but a reference to the control is still valid.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE


Andy said:
Hi,
I have a problem with closing a form, when I'm clicking 'x' button,
the form is still visible.
My form has functionality like TabControl. When I add a new control, all
controls are deleted from the form control collection,
(this.Controls.Clear(); this.Controls.Add( c ) ), but old controls aren't
disposed but added to the queue (Private object on the form of
System.Collection.Queue() class).

After adding the new control, I move focus to this control. Property
ActiveControl of the form is set to null. Where may be a problem?

Regards,
Andy
 
Back
Top