Imagine calling the following C# code:
MessageBox.Show(this, "Some text...", "Title", MessageBoxButtons.OKCancel);
After executing this line, the Message Box is not visible, it seems like hidden behind your form, without input focus, mouse clicks cause default beeps, and it suddenly appears if you click Alt or F10 key.
It turns out I had a custom drawing routine for one of the form’s controls (OwnerDraw / OnPaint), and I was changing the property that was causing the redraw cycle. Make sure, that in your OnPaint / DrawItem / DrawSubitem / etc. you are not invalidating your Control.
Also, if you are using .NET ListView control, it has a bug.
Because of a bug in the underlying Win32 control, the DrawItem event occurs without accompanying DrawSubItem events once per row in the details view when the mouse pointer moves over the row, causing anything painted in a DrawSubItem event handler to be overpainted by a custom background drawn in a DrawItem event handler. See the example in the OwnerDraw reference topic for a workaround that invalidates each row when the extra event occurs. An alternative workaround is to put all your custom drawing code in a DrawSubItem event handler and paint the background for the entire item (including subitems) only when the DrawListViewSubItemEventArgs.ColumnIndex value is 0.
This is not limited to MessageBox using C# / .NET framework. This also happens very often, with Win32 & WinAPI, with a Form class, etc.:
- Dialog MessageBox sometimes hidden behind the main form
- MessageBox.Show Focus Problem
- DoModal hangs until press ALT key
- ALT + TAB is not working after displaying MessageBox on modal dialog…
- C++ Dialog launched from C# does not get focus on Opening
- Modal common dialog not showing until pressing the alt key
- MessageBox sometimes hidden behind the main form
- MessageBox stays hidden until the parent form refocuses
- Messagebox appears behind form
- Hi there, All modal dialogs suddenly started appearing BEHIND a PictureBox, making it look like the application has crashed. Pressing the Alt key brings them to the front…
- messagebox goes behind grid …in ownerdraw handling..