private void notifyIcon1_Click(object sender, System.EventArgs e) 

NotifyIcon eventSource = null; 
Type niHandle = null; 
eventSource = (NotifyIcon)sender; 
niHandle = eventSource.GetType(); 
                     Invoke the private ShowContextMenu method. 
niHandle.InvokeMember( 
"ShowContextMenu", 
BindingFlags.Instance | 
BindingFlags.NonPublic | 
BindingFlags.InvokeMethod, 
null, 
eventSource, 
null 
); 

解决方案 »

  1.   

    using System;
    using System.Windows.Forms;  // NotifyIcon
    using System.Drawing;        // Iconnamespace CSharpNotifyIconWithoutForm
    {
     /// <summary>
     /// Summary description for ClassNotity.
     /// </summary>
     public class ClassNotity
     {
      public ClassNotity()
      {
       //
       // TODO: Add constructor logic here
       //
      }  public static NotifyIcon aAppIcon = new NotifyIcon();
      public static ContextMenu aSysTrayMenu = new ContextMenu();
      public static MenuItem aDisplayInfo = new MenuItem("Info über...");
      public static MenuItem aExitApp = new MenuItem("Beenden");  static void Main()
      {
       Icon aIcon = new Icon(@"NOTES.ICO");
       aAppIcon.Icon = aIcon;
       // MENU zuweisen
       aExitApp.Click += new System.EventHandler(ExitApp_Click);
       aSysTrayMenu.MenuItems.Add(aDisplayInfo);
       aDisplayInfo.Click += new System.EventHandler(DisplayInfo_Click);
       aSysTrayMenu.MenuItems.Add(aExitApp);
       aAppIcon.ContextMenu = aSysTrayMenu;
       // ToolTip-Text zuweisen
       aAppIcon.Text = "C# und NotifyIcon";
       // ICON in der Task Bar Notification Area (TBNA) anzeigen
       aAppIcon.Visible = true;
       // Anwendung starten
       Application.Run();
      }  private static void DisplayInfo_Click(object sender, System.EventArgs e)
      {
       MessageBox.Show("NotifyIcon ohne Formular", "Text",
                                MessageBoxButtons.OK);
      }  private static void ExitApp_Click(object sender, System.EventArgs e)
      {
       aAppIcon.Dispose();
       Application.Exit();
      }
     }
    }