Results 1 to 9 of 9

Thread: Formless Tray Application

Threaded View

  1. #1

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Formless Tray Application

    C# version here.

    Recently, I replied to a thread on another forum where the poster asked how to create an application that displayed an icon in the notification area (aka system tray) but didn't require a form to be created and hidden. My first thought was that a form was required but, upon reflection, I thought that there must be another way. I recalled having read something about the ApplicationContext class so I investigated that further and that is indeed the way to do it.

    Generally, whether you create your own Main method or you use the VB application framework (which hides the main method from you, but it's there) you call Application.Run and pass a form as an argument, which becomes the application's main form. You can also pass an object whose type inherits ApplicationContext as an argument to Application.Run. The application will then close when you call Application.Exit or Application.ExitThread.

    The example attached below meets the requirements of the poster of the aforementioned thread. They wanted a NotifyIcon and the ability to use an OpenFileDialog. For that, I created a component that provided a designer, which made it easy to configure the NotifyIcon and the ContextMenuStrip. My derived ApplicationContext then creates an instance of that component and duly disposes it when the ApplicationContext itself is disposed.

    Simply run the app and you will see the NotifyIcon. Right-click the icon to get a menu that provides items to display an OpenFileDialog and to exit the app.

    Finally, note that the attached application was written in VB 2010, so you will need VS 2010 or VB Express 2010 or later to open it.

    EDIT:

    I have added a version of the demo that uses the RegisterHotKey API.
    Attached Files Attached Files
    Last edited by jmcilhinney; Dec 14th, 2021 at 10:23 PM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width