Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Windows 7 (x64, but the app is x86) (And two different machines.)

Whenever I use a built-in dialog (or MessageBox, for that matter) is does not appear.

I've tried both .ShowDialog() and .ShowDialog(this) to no avail.

BUT, if I briefly tap the ALT key after the dialog is supposed to show up, it magically appears. Likewise if I open, close, move any other application that's available. For instance, IE or Chrome. It's like the system is waiting until something else happens before showing the dialog.

I've eliminated the use of MessageBox by making my own, so that's not a problem anymore... But I don't have an alternative to the FolderBrowserDialog.

What the heck is going on? Any ideas?
Posted
Updated 14-Oct-13 5:48am
v2
Comments
OriginalGriff 14-Oct-13 12:02pm    
Have you checked your threading?
I've had odd effects when trying to show dialogs from non-UI threads (but mostly you get a "bad thread" exception)
GenJerDan 14-Oct-13 16:02pm    
What it is doing is main form "Form A" opens "Form B" modally, which pops up the FolderBrowserDialog modally when a button is pushed. I have not explicitly created any threads. Is Windows/VS doing it behind my back?
pasztorpisti 14-Oct-13 16:56pm    
Does the dialog have a parent wnd?
GenJerDan 14-Oct-13 20:32pm    
Yes. Tried with and without. No difference.
OriginalGriff 15-Oct-13 3:52am    
Don't think so.
I just tried your system in my code:
Main form has a button, which uses ShowDialog to show a Modal form of my design.
On that form there is a button, which opens a FolderBrowserDialog via ShowDialog.
It works fine in an x86 app on Win7/64 for me, without any threading (with threading I get a
"Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process." exception in the debugger).
What are you doing that is different?

1 solution

OK. Weird problem, weird solution.

The menu on the main form had a custom renderer:

private class MyRenderer : ToolStripProfessionalRenderer
{
protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e)
{
if (!e.Item.Selected)
{
base.OnRenderMenuItemBackground(e);
e.Item.ForeColor = Color.White;
e.Item.BackgroundImage = AMSIOS.Properties.Resources.BGTile;
}
else
{
e.Item.ForeColor = Color.Black;
e.Item.BackgroundImage = AMSIOS.Properties.Resources.BG;
Rectangle rc = new Rectangle(Point.Empty, e.Item.Size);
e.Graphics.FillRectangle(Brushes.DarkGray, rc);
e.Graphics.DrawRectangle(Pens.White, 1, 0, rc.Width - 2, rc.Height - 1);
}
}
}

Tracing through the execution (F11, rather than F10) and I saw the main menu was being redrawn and redrawn and redrawn for no apparent reason. The main form isn't even accessible at that point, so why was it rerendering it? Now I just have to figure out why that (stolen) code caused the dialog box problems.

Thanks, all.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900