MessageBox appears behind forms

G

Guest

Hello,

I have an application which consists of 11 forms. At times I use the
MessageBox.Show(owner, ...) to display messages or ask questions of the user.
The application often gets into a state where these boxes appear behind the
forms instead of in front of them. e.g. I click the cross in the main form
to close the application. The form closing event handler displays a message
box asking "are you sure?" with a choice of yes or no. However, instead of
appearing in front of the forms, the message box will appear behind them.
Once this occurs once, it seems to happen all the time. I have no idea what
could cause this...

Thanks,

David
 
G

Guest

Thanks for the reply Thomas. Unfortunately the TopMost property is set to
false for all of the forms.

I have two other problems which may or may not be related:

1.
Some of the forms seem to stop repainting. They are all updated in response
to change events. Most contain grids (third party) but some contain just
labels and text boxes. Some of the forms just stop repainting. This can be
seen as if I open up another window (say the Performance counter window from
the windows admin tools) and drag it over my apps forms then most of them
(but not all, and different ones each time) do not repaint. I know they are
receiving the change events as I added in a line to change the form titlebar
text to the current DateTime every time it receives a change event. I can
see that the time has been incremented in the taskbar if I bring up the list
of the forms (they are grouped as there is 11) and most of them receive
change events nearly every second. Clicking/moving the forms causes them to
repaint. Some times clicking/moving one form appears to cause all the dead
forms to repaint, sometimes they all have to be clicked.

This problem occurs every single time the application is run. I have tried
placing form.Update after the change event has been processed to force a
repaint and this works but I imagine it does so at a heavy cost in
performance. Besides, this only works if the form has changed. Some of them
may not change for minutes at a time and I cannot have them blanked out if
the user happens to drag another window over them.

2.
The main application form opens the 10 other forms. They are constructed
and displayed in a for loop in response to a button press. The main form
holds a reference to each of the other forms and they each hold a reference
to the main form. This reference holding is achieved via a simple parent
class that inherits from the system.windows.forms.form class.

The problems is that sometimes the forms do not all appear in the windows
taskbar. They are opened correctly and appear to work (besides the
repainting and message box problems noted above) but just do not appear in
the taskbar. When clicked for the first time, they appear in the taskbar.

---
I have a feeling that these three problems are somehow related. That they
are symptoms of the real problem. The message box problem never seems to
appear without the repainting problem. It occurs far more often now that i
have taken out the workarounds for the repaint issue. Also, the problem with
the forms not appearing in the taskbar seems to suggest that there is some
problem with their startup - perhaps it is something here that causes them to
not repaint?

I don't know. If anyone has any insights here it would be greatly
appreciated. I have had these problems on and off for months and worked
around them but I must now find the cause and get rid of them.

Thanks for any help,

David
 
T

thomas woelfer

David,
Thanks for the reply Thomas. Unfortunately the TopMost property is set to
false for all of the forms.

maybe some is changing it at runtime ?
change events nearly every second. Clicking/moving the forms causes them to
repaint. Some times clicking/moving one form appears to cause all the dead
forms to repaint, sometimes they all have to be clicked.

this sounds like the actual painting is done in an idle event handler. one thing
you should do is ensure OnPaint() actually gets called...
may not change for minutes at a time and I cannot have them blanked out if
the user happens to drag another window over them.

strange. sounds as if the form tells the system there's no invalidated rect
on it. thus, nothing gets repainted. i have no other explanation for repaints
to stop completely. i assume there's some mechanism that calculates
the invalid rectangle, and that mechanism doesn't work. maybe this even
happens inside an idle handler, which would explain some other symptoms
you describe.
The problems is that sometimes the forms do not all appear in the windows
taskbar. They are opened correctly and appear to work (besides the
repainting and message box problems noted above) but just do not appear in

i think, not beeing shown in the taskbar and not repainting is essentially the same
problem. the forms simply don't tell the base class there is stuff that needs
painting, thus nothing gets painted.

so i guess you should take a look at:
- idle handlers
- stuff that is supposed to calculate the invalidation rectangle
- OnPaint overloads

WM_HOPETHISHELPS
thomas woelfer
http://www.die.de/blog
 

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