C# タスクトレイに常駐
[C#][Visual Studio]
コントロールの配置とプロパティの設定
- NotifyIcon および ContextMenuStrip を配置
- アイコンの作成
- ソリューションエクスプローラーからアイコンを追加し、適当に作成
- NotifyIconのIconプロパティ作成したアイコンを選択
- ContextMenuStripにメニュー追加
イベントハンドラの作成
- NotifyIcon のダブルクリックで画面の復帰を行う
- Form の Closingイベントでタスクトレイに入れる。
ソースコード
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(); } } }
YAGI Hiroto (piroto@a-net.email.ne.jp)
twitter http://twitter.com/pppiroto
Copyright© 矢木 浩人 All Rights Reserved.