2012-09-14 6 views
8

私は数年前からunity3DでC#をスクリプト化しましたが、C#のプログラミングにはとても新しいです。 私は現在、しかし.Formsは私にとってSystem.Windowsでは使用できませんwpfを使用したC#trayicon

System.Windows.Forms 

を使用するように教えて、WPFのトレイアイコンを作るために、私はネット上で見つけたすべてのソースをしようとしている、と私は持っていますどうしていいかわからない。誰もこれで私を助けることができますか?

答えて

25

あなたはこのようにそれを使用し、その後System.Window.FormsとたSystem.Drawingアセンブリへの参照を追加する必要があります。ウィンドウアイコンを最小化し、ユーザーがそのアイコンをクリックしたときに再び表示しようとしたとします。

public partial class Window : System.Windows.Window 
{ 

    public Window() 
    { 
     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 == WindowState.Minimized) 
      this.Hide(); 

     base.OnStateChanged(e); 
    } 
} 
+0

優れた言葉遣いで、方法と場所を知ることができました。 そして、私はトレイアイコンを持っています、thanks =) – Logan

+2

System.Windowsリファレンスを持つウィンドウに表示されている場合は、あいまいさの問題が発生します。私はそれに名前を付け加えることでそれを解決しました:using WinForms = System.Windows.Forms;次に、WinForms.NotifyIcon notifyIcon = new WinForms.NotifyIcon();でそれを呼び出します。 –

関連する問題