Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Show a modeless form from an app with no main form?

Show a modeless form from an app with no main form?

Scheduled Pinned Locked Moved C#
questiondockeralgorithmshelptutorial
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    John Whitmire
    wrote on last edited by
    #1

    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 of Application.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 use Form.ShowDialog(), the form appears, but blocks the user interaction that is associated with the NotifyIcon.ContextMenu and I have no way to remove it. If I use Form.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?

    J 1 Reply Last reply
    0
    • J John Whitmire

      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 of Application.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 use Form.ShowDialog(), the form appears, but blocks the user interaction that is associated with the NotifyIcon.ContextMenu and I have no way to remove it. If I use Form.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?

      J Offline
      J Offline
      John Whitmire
      wrote on last edited by
      #2

      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 call Application.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 with Invoke 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?

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups