Show a modeless form from an app with no main form?
-
Copying an example I found, I have a Windows application with no main form that just manages a NotifyIcon in the tray with its small context menu functions. As such, its Main has
Application.Run()
instead ofApplication.Run(someform)
. That part works fine. Now I need it to conditionally show/hide a form. There are no user interaction controls on the form (it's display only) and the "default" condition is to have the form hidden. If I useForm.ShowDialog()
, the form appears, but blocks the user interaction that is associated with theNotifyIcon.ContextMenu
and I have no way to remove it. If I useForm.Show()
to keep the user interaction with NotifyIcon functional, the form appears but none of its contained controls render and it forever shows the Wait cursor. After much fruitless searching for a threading issue (even though InvokeRequired is always false), I came across a clue that it might instead be a message pump issue. This makes some sense (since I can fully show and hide the form if I do it within the ContextMenu event handlers), but I can't find enough info to compose a candidate solution. How do I get this form to complete its rendering without making it modal? -
Copying an example I found, I have a Windows application with no main form that just manages a NotifyIcon in the tray with its small context menu functions. As such, its Main has
Application.Run()
instead ofApplication.Run(someform)
. That part works fine. Now I need it to conditionally show/hide a form. There are no user interaction controls on the form (it's display only) and the "default" condition is to have the form hidden. If I useForm.ShowDialog()
, the form appears, but blocks the user interaction that is associated with theNotifyIcon.ContextMenu
and I have no way to remove it. If I useForm.Show()
to keep the user interaction with NotifyIcon functional, the form appears but none of its contained controls render and it forever shows the Wait cursor. After much fruitless searching for a threading issue (even though InvokeRequired is always false), I came across a clue that it might instead be a message pump issue. This makes some sense (since I can fully show and hide the form if I do it within the ContextMenu event handlers), but I can't find enough info to compose a candidate solution. How do I get this form to complete its rendering without making it modal?I found something that works, but I'd like to know if this was really the preferred solution since it seems a bit awkward to me. However, this solution does support the message pump hypothesis I mentioned in my question. In the constructor for the form that I want to display, I start up an auto-reset
Timer
that fires every 200 (for now) ms. In the timer event handler, I callApplication.DoEvents()
. That's all it took... a surrogate message pump! :cool: Additionally, the Show, Hide, Close, and content update actions all had to be wrapped withInvoke
boilerplate, but that makes sense. Wildly simple, but was there a better way? If I had two forms to show, would each require its own timer solution?