Dynamically remove control bug ...

  • Thread starter Thread starter Romain TAILLANDIER
  • Start date Start date
R

Romain TAILLANDIER

Hi group.

I have a strange problem that need a long explaination, sorry.

I have a form where i dynamically create lines (class Ligne : Panel ).

Lines are composed by
- a RadioButton, which is used to send a select event (to select the line).
- a red cross Button, wich used to send a delete event (to remove the line)

When i clic to the RadioButton, I send the SelectEvent
MainForm is listenning to it, and launch the select method.
When I clic the redCrossButton, I send the event SupprEvent.
MainForm is listenning to it, and launch the remove method.

The graphic interface is composed with 2 boutons that allow to dynamically
add a line; and dynamically remove the selected line.

So to Remove a line I have 2 ways :
- Clic on the red cross of a line (delete a selected or not selected line)
- Clic on the bouton Remove (delete the selected line)

Finally, the two way call for the same MainForm.RemoveLine method to remove
the line. One comming from the MainForm.RemoveBoutton_click method, the
other comming from the MainForm.ListernerForRemoveEvent method.

the MainForm.RemoveLine method call to Windows.Form.Controls.RemoveAt()
method.
And all seem to work fine.

But there is a difference. when i remove a line by clicking on the red cross
(MainForm.ListernerForRemoveEvent method) , the call to
Form.Controls.RemoveAt() cause a bug, that isn't caused when calling by the
clic on Remove button (MainForm.RemoveBoutton_click method). this bug is
that i can't anymore close the form by click in the top-rigth-corner-cross
of the form.

What i do, that i must not ??

So i think the problem is strange, and i create a minimalist application
that reproduce the bug. but it still remain a lot of necessary code. and
that code is documented in french :p.
I am ok to send it if necessary.

For Gabriel G. Ponti,
sorry to make so much time for responding. :)

Thank you
ROM
 
ROM,
What i do, that i must not ??

I think it could be due to how the events are handled, like you are trying
to remove a control that is still running some code.

I can take a look at the code if you want.

Gabriele
 
ROM,

Thank you for providing the source code and taking time to translate the
comments in English. I run the executable that you provided and I was able
to see the problem.

However when I run the sample from Visual Studio .NET 2003 it worked
correctly. This lead me to think that there is an issue of version 1.0 of
the framework. To make sure I forced the 1.0 runtime for the project, and
indeed the problem reappeared.

It seems to me that after removing the control the form stops processing the
WM_CLOSE message (or it's processed but fails) so the form stays open. I
noticed that the form can still be closed via Application.Exit(), from a
button on the form for example.

If you can't or don't want to upgrade to Visual Studio .NET 2003, you can
either provide a button to close the form, or redesign your application
turning your controls into User Controls.

Regards,

Gabriele
 
Gabriele,

I have seen (just yersterday) that the bug was fixed in .net 2003 but
have'nt have time to signal it...

thank you for your advices.
Can i put the Application.exit in the .dispose method of the form ?

ROM
 
Can i put the Application.exit in the .dispose method of the form ?

Dispose() isn't even called, because trying to close the form won't process
as usual.
 
Back
Top