トップ 一覧 ping 検索 ヘルプ RSS ログイン

C# タスクトレイに常駐の変更点

  • 追加された行はこのように表示されます。
  • 削除された行はこのように表示されます。
!!!C# タスクトレイに常駐
[C#][Visual Studio]
!!コントロールの配置
!!コントロールの配置とプロパティの設定
::NotifyIcon および ContextMenuStrip を配置
{{ref_image tasktray01.jpg}}
::アイコンの作成
*ソリューションエクスプローラーからアイコンを追加し、適当に作成
{{ref_image tasktray02.jpg}}
::NotifyIconのIconプロパティ作成したアイコンを選択
{{ref_image tasktray03.jpg}}
::NotifyIconのContextMenuStripプロパティに追加したContextMenuStripを指定
{{ref_image tasktray04.jpg}}
*ContextMenuStripにメニュー追加
{{ref_image tasktray06.jpg}}

::
{{ref_image tasktray05.jpg}}
!!イベントハンドラの作成
::NotifyIcon のダブルクリックで画面の復帰を行う
{{ref_image tasktray07.jpg}}
::Form の Closingイベントでタスクトレイに入れる。
{{ref_image tasktray08.jpg}}
!!ソースコード
 using System;
 using System.ComponentModel;
 using System.Windows.Forms;
 
 namespace TaskTraySample
 {
     public partial class Form1 : Form
     {
         public Form1()
         {
             InitializeComponent();
         }
         private void Form1_FormClosing(object sender, FormClosingEventArgs e)
         {
             e.Cancel = true;
             this.Visible = false;
         }
         private void exitToolStripMenuItem_Click(object sender, EventArgs e)
         {
             this.Dispose();
         }
         private void notifyIcon1_DoubleClick(object sender, EventArgs e)
         {
             this.Visible = true;
             this.Activate();
         }
     }
 }
!!できた
{{ref_image tasktray05.jpg}}