Form Not Respond To Mouse Click

M

moonie

I have an msn style c# windows application with a form and panel on
it.
A news list is drawn from the database and dynamically added via
labels, link lables during form loading. In this application at run
time this list should be generated again as the filtering criteria
changes. So I clear the controls(labels) on the panel, get the list
from the database and generate the list again. The list is created
and
it works fine. But sometimes the form begins not to respond to mouse
clicks. Only mouse over and mousemove events work. Does anybody have
suggestions on why this happens?
 
K

Kevin Spencer

A mouse click is handled by a Control, not by the Form, unless there is no
Control in the location of the mouse click. If the Control does not have the
focus, the first mouse click will focus on the Control, and the second will
cause the Click event.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

I had the same problem once. Fixed it using the same solution.
 
M

moonie

Thanks for your answer Kevin.
But I did not understand what should I do to fix the problem :)
I placed this.Refresh();this.Activate(); in the form code but it
did'nt help.
Also I should inform you that there are three panels on the form and
the labels, buttons etc. are on these panels.
 
M

moonie

I found the solution :) I called Panel.Controls.Clear() method to
remove the labels and links. That is why the controls were not
disposed and their event handlers were not removed. So when I added
new controls with same event handlers somehow it got confused and the
click event did not work. Now I call Panel.Control.Dispose() for
every control on the panel and add new controls and it works great!
 
M

moonie

I found the solution :) I called Panel.Controls.Clear() method to
remove the labels and links. That is why the controls were not
disposed and their event handlers were not removed. So when I added
new controls with same event handlers somehow it got confused and the
click event did not work. Now I call Panel.Control.Dispose() for
every control on the panel and add new controls and it works great!
 
K

Kevin Spencer

Good work, moonie. Yes, it is important to dispose of any Controls that are
added to another Control.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

I had the same problem once. Fixed it using the same solution.

I found the solution :) I called Panel.Controls.Clear() method to
remove the labels and links. That is why the controls were not
disposed and their event handlers were not removed. So when I added
new controls with same event handlers somehow it got confused and the
click event did not work. Now I call Panel.Control.Dispose() for
every control on the panel and add new controls and it works great!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top