Skip to content

Instantly share code, notes, and snippets.

@clausjoergensen
Created September 19, 2011 13:14
Show Gist options
  • Save clausjoergensen/1226468 to your computer and use it in GitHub Desktop.
Save clausjoergensen/1226468 to your computer and use it in GitHub Desktop.
using System.ComponentModel;
using System.Windows.Forms;
namespace WindowsFormsApplication
{
public class MainForm : Form
{
private IContainer components;
private NotifyIcon notifyIcon;
public MainForm()
{
this.InitializeComponent();
this.notifyIcon = new NotifyIcon();
this.notifyIcon.Click += (s, e) =>
{
this.WindowState = FormWindowState.Normal;
this.notifyIcon.Visible = false;
};
this.ShowInTaskbar = false;
this.ShowIcon = false;
this.Resize += (s, e) =>
{
if (this.WindowState == FormWindowState.Minimized)
{
this.notifyIcon.Visible = true;
this.notifyIcon.Icon = Properties.Resources.MyNotifyIcon;
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
}
};
}
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
this.components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.components = new Container();
this.AutoScaleMode = AutoScaleMode.Font;
this.Text = "";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment