8

Possible Duplicate:
Writing a Windows system tray application with .NET

Hi,
I am programming an application in .NET and I don't want to put it a windows interface.
I remember some time ago I did it with inheriting from the ApplicationContext class but now I can't achieve it.

How I could do it?

Thanks!

Edit: It's an application that is managed by a notify icon. It must appear the icon near the system clock but not a form. I'm doing this:

class Sync : ApplicationContext
{
    public Sync()
    {
        ...
    }
}

[STAThread]
static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new Sync());
}
Community
  • 1
  • 1
Alfre2
  • 2,039
  • 3
  • 19
  • 22
  • What type of application are you developing? Console window, Windows Service, Library? –  Jun 18 '09 at 11:23
  • 2
    Duplicate? http://stackoverflow.com/questions/995195/writing-a-windows-system-tray-application-with-net – ChrisF Jun 18 '09 at 11:34

4 Answers4

24

(obsolete now that you've edited the question to state systray; left for reference only)

If you want an exe without any UI (not even a console), but without it being a service etc - then write a windows forms app, but just don't show any forms! The fact that it is a winform app simply means you don't get a console window - but no UI is shown except that which you write. Look at the Main method (usually in Program.cs in the VS templates) to see what I mean.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • 1
    So easy. Just delete the form and replace the `Main()`-code. Thanks for this! – C4d Feb 22 '16 at 13:13
9

You can write a Console Application or a Service or something of that sort. What exactly do you want to do?

Aamir
  • 14,882
  • 6
  • 45
  • 69
3

How about using a console application or a Windows Service?

Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541
1

see here: http://bluehouse.wordpress.com/2006/01/24/how-to-create-a-notify-icon-in-c-without-a-form/

Edit: added the code in the link to this answer in case the link dies. Credit goes to the author for this code.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;

class ControlContainer : IContainer
{
    ComponentCollection _components;

    public ControlContainer()
    {
        _components = new ComponentCollection(new IComponent[] { });
    }

    public void Add(IComponent component) { }
    public void Add(IComponent component, string Name) { }
    public void Remove(IComponent component) { }

    public ComponentCollection Components
    {
        get { return _components; }
    }

    public void Dispose()
    {
        _components = null;
    }
}

class MainEntryClass
{
    static void Main(string[] args)
    {
        SomeClass sc = new SomeClass();
        Application.Run();
    }
}

class SomeClass
{
    ControlContainer container = new ControlContainer();
    private System.Windows.Forms.NotifyIcon notifyIcon1;

    public SomeClass()
    {
        this.notifyIcon1 = new NotifyIcon(container);
    }
}
rein
  • 32,967
  • 23
  • 82
  • 106