Hello all, i want to make icon (shortcut to run my program) on System Tray (usually on Right bottom) with code, i'm using visual studio 2008 c#, on classlibrary project, thanks before :D

Dani AI

Generated

gave the quick UI-side answer earlier. A crucial clarification: the Windows notification area (system tray) does not hold static "shortcuts" — it shows icons registered by running processes. That means an executable must be running and hosting a message loop to register a tray icon. For a Class Library (DLL) scenario, the library cannot appear by itself; the library should either be hosted by a small EXE or expose Start/Stop APIs that the host process calls to create and dispose a tray icon.

A compact pattern is to host the tray icon in an ApplicationContext so no visible Form is required. The example below shows a minimal headless tray host using WinForms:

using System;
using System.Windows.Forms;
using System.Drawing;

class TrayApplicationContext : ApplicationContext
{
    private NotifyIcon tray;

    public TrayApplicationContext()
    {
        tray = new NotifyIcon();
        tray.Icon = new Icon("app.ico");        // embed or ship an .ico
        tray.Text = "MyApp";
        tray.ContextMenuStrip = new ContextMenuStrip();
        tray.ContextMenuStrip.Items.Add("Exit", null, (s,e) => Exit());
        tray.Visible = true;
        tray.DoubleClick += (s,e) => { /* restore/show window or open UI */ };
    }

    private void Exit()
    {
        tray.Visible = false;
        tray.Dispose();
        Application.ExitThread();
    }
}

[STAThread]
static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new TrayApplicationContext());
}

For a library that needs to provide a tray interface to whatever hosts it, expose a simple controller with Start/Stop (or IDisposable) that creates/cleans up a NotifyIcon. Important operational notes: create the NotifyIcon on a thread with a message loop (Application.Run or the UI thread); always call Dispose() (or set Visible=false then Dispose) to avoid orphaned icons; embed a proper .ico (16x16/32x32) in resources; Windows may still hide icons by user settings, so presence in the overflow area is normal.

Further reference: NotifyIcon class, ApplicationContext class, Application.Run.

Recommended Answers

All 2 Replies

Hello all, i want to make icon (shortcut to run my program) on System Tray (usually on Right bottom) with code, i'm using visual studio 2008 c#, on classlibrary project, thanks before :D

add a NotifyIcon control to the form. Then you can code the Form_Resize event to hide the form and the doubleclick event of the notifyicon to show the form.

owh that's work, thanks :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.