Skip to content

Instantly share code, notes, and snippets.

@joemaidman
Created March 4, 2016 15:38
Show Gist options
  • Save joemaidman/728783844d6fdc7d05ab to your computer and use it in GitHub Desktop.
Save joemaidman/728783844d6fdc7d05ab to your computer and use it in GitHub Desktop.
Minimse c# window to systemtray
public partial class Window1 : System.Windows.Window
{
public Window1()
{
InitializeComponent();
System.Windows.Forms.NotifyIcon ni = new System.Windows.Forms.NotifyIcon();
ni.Icon = new System.Drawing.Icon("Main.ico");
ni.Visible = true;
ni.DoubleClick +=
delegate(object sender, EventArgs args)
{
this.Show();
this.WindowState = WindowState.Normal;
};
}
protected override void OnStateChanged(EventArgs e)
{
if (WindowState == System.Windows.WindowState.Minimized)
this.Hide();
base.OnStateChanged(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment