Windows フォーム NotifyIcon コンポーネントは、タスク バーの状態通知領域に 1 つのアイコンを表示します。 ステータス領域に複数のアイコンを表示するには、フォームに複数の NotifyIcon コンポーネントが必要です。 コントロールに表示されるアイコンを設定するには、Icon プロパティを使用します。 ユーザーがアイコンをダブルクリックしたときに何かが発生するように、DoubleClick イベント ハンドラーにコードを記述することもできます。 たとえば、ユーザーがアイコンで表されるバックグラウンド プロセスを構成するためのダイアログ ボックスを表示できます。
注
NotifyIcon コンポーネントは、通知目的でのみ使用され、アクションまたはイベントが発生したか、何らかの状態が変更されたことをユーザーに警告します。 メニュー、ツール バー、およびその他のユーザー インターフェイス要素は、アプリケーションとの標準的な対話に使用する必要があります。
アイコンを設定するには
Icon プロパティに値を割り当てます。 値は
System.Drawing.Icon
型である必要があり、.ico ファイルから読み込むことができます。 アイコン ファイルは、コードで指定するか、The Ellipsis button (...) in the Properties window of Visual Studio.[プロパティ] ウィンドウの Icon プロパティの横にある省略記号ボタン () をクリックし、表示される [開く] ダイアログ ボックスでそのファイルを選んで指定することができます。
Visible プロパティを
true
に設定します。Text プロパティを適切なツールヒント文字列に設定します。
次のコード例では、アイコンの場所に設定されたパスは、[マイ ドキュメント] フォルダー
です。 この場所は、Windows オペレーティング システムを実行しているほとんどのコンピューターにこのフォルダーが含まれると想定できるために使用されます。 この場所を選択すると、最小限のシステム アクセス レベルを持つユーザーがアプリケーションを安全に実行することもできます。 次の例では、NotifyIcon コントロールが既に追加されているフォームが必要です。 また、 Icon.ico
という名前のアイコン ファイルも必要です。' You should replace the bold icon in the sample below ' with an icon of your own choosing. NotifyIcon1.Icon = New _ System.Drawing.Icon(System.Environment.GetFolderPath _ (System.Environment.SpecialFolder.Personal) _ & "\Icon.ico") NotifyIcon1.Visible = True NotifyIcon1.Text = "Antivirus program"
// You should replace the bold icon in the sample below // with an icon of your own choosing. // Note the escape character used (@) when specifying the path. notifyIcon1.Icon = new System.Drawing.Icon (System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal) + @"\Icon.ico"); notifyIcon1.Visible = true; notifyIcon1.Text = "Antivirus program";
// You should replace the bold icon in the sample below // with an icon of your own choosing. notifyIcon1->Icon = gcnew System::Drawing::Icon(String::Concat (System::Environment::GetFolderPath (System::Environment::SpecialFolder::Personal), "\\Icon.ico")); notifyIcon1->Visible = true; notifyIcon1->Text = "Antivirus program";
こちらも参照ください
.NET Desktop feedback