0
我想创建一个只有自定义托盘图标可见的C#应用程序,没有别的。没有主窗体,没有托盘图标菜单,只是图标。最简单的方法是什么?如何创建基本的托盘图标应用程序?
我想我应该从一个控制台应用程序开始,因为我不需要任何表单。到目前为止,我只找到了如何在WinForms应用程序中隐藏主窗体的复杂示例,以及许多其他不必要的内容。
我想创建一个只有自定义托盘图标可见的C#应用程序,没有别的。没有主窗体,没有托盘图标菜单,只是图标。最简单的方法是什么?如何创建基本的托盘图标应用程序?
我想我应该从一个控制台应用程序开始,因为我不需要任何表单。到目前为止,我只找到了如何在WinForms应用程序中隐藏主窗体的复杂示例,以及许多其他不必要的内容。
您可以创建一个应用程序上下文:
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new TrayApplicationContext());
}
}
public class TrayApplicationContext : ApplicationContext
{
private readonly NotifyIcon _trayIcon;
public TrayApplicationContext()
{
_trayIcon = new NotifyIcon
{
//it is very important to set an icon, otherwise you won't see your tray Icon.
Icon = Resources.AppIcon,
Visible = true
};
}
}
有一些问题,正确添加图标的资源,但后来这一切工作。 – user1306322
你看过吗? http://stackoverflow.com/questions/995195/how-can-i-make-a-net-winforms-application-that-only-runs-in-the-system-tray – Matthias