Feeds:
Posts
Comments

Archive for September, 2007

To use an icon resource embedded into your assemply: 
1) Add icon to project and make it an “Embedded Resource” type (no need to copy to output directory).
2) Construct your System.Drawing.Icon like this:

new Icon(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(“MyShinyApp.hammer.ico”));

Where MyShinyApp is the value specified in “Default namespace” property of your project (Application tab of project properties) and hammer.ico is the name [...]

Read Full Post »

Minimize to tray icon in WPF

I had to do a bit of searching so, here’s how to minimize your WPF app to a tray icon.  Assume your window is called Window1 for the code below.  Trap Closing, StateChanged and IsVisibleChanged (see xaml). 
xaml:

<window x:Class=”MyApp.Window1″ xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
  xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
  Title=”WCFAppVisualHost” Height=”383″ Width=”680″ Closing=”OnClose” StateChanged=”OnStateChanged” IsVisibleChanged=”OnIsVisibleChanged”
  >

Associated cs:

private System.Windows.Forms.NotifyIcon m_notifyIcon;
public Window1()
{     // initialise code here
    m_notifyIcon = new System.Windows.Forms.NotifyIcon();
    [...]

Read Full Post »