C Sharp タスクトレイに常駐
ナビゲーションに移動
検索に移動
C# タスクトレイに常駐
C Sharp | Visual Studio |
コントロールの配置とプロパティの設定
NotifyIcon および ContextMenuStrip を配置
アイコンの作成
- ソリューションエクスプローラーからアイコンを追加し、適当に作成
NotifyIconのIconプロパティ作成したアイコンを選択
NotifyIconのContextMenuStripプロパティに追加したContextMenuStripを指定
- 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();
}
}
}
できた
© 2006 矢木浩人







