Recently I just started using C# again, so I was brushing up on what I knew and experimenting with some new options. One of those is the Component NotifyIcon. There are not many tutorials that deal with compiling C# with csc.exe, so I resorted to Microsoft's Code. I got the source for their example, and attempted to compile it. ( csc /target:winexe Form1.cs ) It compiled perfectly, but when I ran it I got a nondescript error that it wanted to send to Microsoft. Details I got were:
EventType : clr20r3 P1 : form1.exe P2 : 0.0.0.0 P3 : 46109285
P4 : mscorlib P5 : 2.0.0.0 P6 : 4333ab80 P7 : 32f8 P8 : d8
P9 : system.io.filenotfoundexception
I have the env. path to the framework correct.
Using v2.0.50727 of .Net Framework.
Sourcecode:
using System;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
namespace Form1{
public class Form1 : Form
{
private NotifyIcon notifyIcon1;
private ContextMenu contextMenu1;
private MenuItem menuItem1;
private IContainer components;
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
public Form1()
{
this.components = new Container();
this.contextMenu1 = new ContextMenu();
this.menuItem1 = new MenuItem();
this.contextMenu1.MenuItems.AddRange(
new MenuItem[] {this.menuItem1});
this.menuItem1.Index = 0;
this.menuItem1.Text = "E&xit";
this.menuItem1.Click += new EventHandler(this.menuItem1_Click);
this.ClientSize = new Size(292, 266);
this.Text = "Notify Icon Example";
this.notifyIcon1 = new NotifyIcon(this.components);
notifyIcon1.Icon = new Icon("appicon.ico");
notifyIcon1.ContextMenu = this.contextMenu1;
notifyIcon1.Text = "Form1 (NotifyIcon example)";
notifyIcon1.Visible = true;
notifyIcon1.DoubleClick += new EventHandler(this.notifyIcon1_DoubleClick);
}
protected override void Dispose( bool disposing )
{
if( disposing )
if (components != null)
components.Dispose();
base.Dispose( disposing );
}
private void notifyIcon1_DoubleClick(object Sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
this.WindowState = FormWindowState.Normal;
this.Activate();
}
private void menuItem1_Click(object Sender, EventArgs e) {
this.Close();
}
}
}