1,670 バイト追加
、 2020年2月15日 (土) 07:30
==C# タスクトレイに常駐==
[C#][Visual Studio]
===コントロールの配置とプロパティの設定===
=====NotifyIcon および ContextMenuStrip を配置=====
[[File:0268_tasktray01.jpg]]
=====アイコンの作成=====
*ソリューションエクスプローラーからアイコンを追加し、適当に作成
[[File:0269_tasktray02.jpg]]
=====NotifyIconのIconプロパティ作成したアイコンを選択=====
[[File:0270_tasktray03.jpg]]
=====NotifyIconのContextMenuStripプロパティに追加したContextMenuStripを指定=====
[[File:0271_tasktray04.jpg]]
*ContextMenuStripにメニュー追加
[[File:0273_tasktray06.jpg]]
===イベントハンドラの作成===
=====NotifyIcon のダブルクリックで画面の復帰を行う=====
[[File:0274_tasktray07.jpg]]
=====Form の Closingイベントでタスクトレイに入れる。=====
[[File:0275_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();
}
}
}
===できた===
[[File:0272_tasktray05.jpg]]