Form can't be closed
-
Hi, I'm adding some controls on
Panel
at runtime. This works fine, but after removing this controls, Application can't be closed (andClosing
event isn't called). :omg: Creating controls:MyControl ctrl=new MyControl(); // MyControl is derived from UserControl
ar.Add(ctrl);
panel1.Controls.Add(ctrl);Removing all controls:
panel1.Controls.Clear();
foreach(MyControl ctrl in ar) ctrl.Dispose();
ar.Clear();When I'm not removing controls it works :confused: i'm only pointer to myself
-
Hi, I'm adding some controls on
Panel
at runtime. This works fine, but after removing this controls, Application can't be closed (andClosing
event isn't called). :omg: Creating controls:MyControl ctrl=new MyControl(); // MyControl is derived from UserControl
ar.Add(ctrl);
panel1.Controls.Add(ctrl);Removing all controls:
panel1.Controls.Clear();
foreach(MyControl ctrl in ar) ctrl.Dispose();
ar.Clear();When I'm not removing controls it works :confused: i'm only pointer to myself
Tomas Petricek wrote: MyControl ctrl=new MyControl(); // MyControl is derived from UserControl ar.Add(ctrl); panel1.Controls.Add(ctrl); You are duplicating code..... Tomas Petricek wrote: panel1.Controls.Clear(); foreach(MyControl ctrl in ar) ctrl.Dispose(); ar.Clear(); It seems the GC might be invoked too early, therefore modifying the collection while enumerating thru it, which is illegal. Rather use a while loop:
while (Controls.Count > 0)
{
Control ctrl = Controls[0];
Controls.Remove(ctrl);
ctrl.Dispose();
}Hope this helps :) Who is this miscrosoft, and what devilish plans have they for us?
-
Hi, I'm adding some controls on
Panel
at runtime. This works fine, but after removing this controls, Application can't be closed (andClosing
event isn't called). :omg: Creating controls:MyControl ctrl=new MyControl(); // MyControl is derived from UserControl
ar.Add(ctrl);
panel1.Controls.Add(ctrl);Removing all controls:
panel1.Controls.Clear();
foreach(MyControl ctrl in ar) ctrl.Dispose();
ar.Clear();When I'm not removing controls it works :confused: i'm only pointer to myself
I heard somewhere that this can happen if controls are hidden.
Paul Watson wrote: "At the end of the day it is what you produce that counts, not how many doctorates you have on the wall."
George Carlin wrote: "Don't sweat the petty things, and don't pet the sweaty things."
-
Hi, I'm adding some controls on
Panel
at runtime. This works fine, but after removing this controls, Application can't be closed (andClosing
event isn't called). :omg: Creating controls:MyControl ctrl=new MyControl(); // MyControl is derived from UserControl
ar.Add(ctrl);
panel1.Controls.Add(ctrl);Removing all controls:
panel1.Controls.Clear();
foreach(MyControl ctrl in ar) ctrl.Dispose();
ar.Clear();When I'm not removing controls it works :confused: i'm only pointer to myself
There is a bug where a Form can't be closed if you remove a control that has the current focus. James "It is self repeating, of unknown pattern" Data - Star Trek: The Next Generation
-
There is a bug where a Form can't be closed if you remove a control that has the current focus. James "It is self repeating, of unknown pattern" Data - Star Trek: The Next Generation
Thank you ! Setting focus to another control solved my problem. :) i'm only pointer to myself