Windows Azure Cloud Storage ermöglicht es Ihnen bereits ab 0,10€ pro GB/Monat die Vorteile der Cloud zu nutzen.
Willkommen bei dotnet-snippets.de! Snippet hinzufügen Login Registrieren
Snippets in der Datenbank: 1551 | Anzahl registrierter User: 1841 | Besucher online: 262
Hauptmenü
Home
Top Ten
Zufälliger Snippet
FAQs
.NET Community
dotnet-forum.de
dotnet-kicks.de
Social

RSS Feeds
Rss Alle Snippets
Rss C#
Rss VB.NET
Rss C++
Rss ASP.NET
Partner
Member of Microsoft Community Leader/Insider Program (CLIP)

Vorlage für Tray-/NotifyIcon-Anwendung


Autor: herbivore
Sprache: C#
Bewertung:
8.11 (2 votes)
Anzahl der Aufrufe: 24985
  
Kick it on dotnet-kicks.de  

Beschreibung:

Das folgende Snippet ist eine Vorlage für eine Anwendung, die beim Start ein NotifyIcon mit Kontextmenü erzeugt, aber kein Form öffnet. Das Öffnen von Forms ist aber über das Kontextmenü nachträglich möglich.

NotifyIcons sind die kleinen Symbole unten rechts in der Taskleiste (Tray).

Damit eignet sich diese Vorlage für Anwendungen, bei denen das NotifyIcon und nicht die Forms im Vordergrund stehen.


Abgelegt unter: NotifyIcon, Tray, Systemtray, Statusbereich, Taskbar, Taskleiste, Programmleiste, Icon, Symbol, ContextMenu, Kontextmenü, Anwendung, Programm, Anwendungsrahmen, Programmrahmen.



C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Windows.Forms;
using System.Drawing;

//*****************************************************************************
static class MyNotifyIconApplication
{
   private static NotifyIcon  notico;

   //==========================================================================
   public static void Main (string [] astrArg)
   {
      ContextMenu cm;
      MenuItem    miCurr;
      int         iIndex = 0;

      // Kontextmenü erzeugen
      cm = new ContextMenu ();

      // Kontextmenüeinträge erzeugen
      miCurr = new MenuItem ();
      miCurr.Index = iIndex++;
      miCurr.Text = "&Aktion 1";           // Eigenen Text einsetzen
      miCurr.Click += new System.EventHandler (Action1Click);
      cm.MenuItems.Add (miCurr);

      // Kontextmenüeinträge erzeugen
      miCurr = new MenuItem ();
      miCurr.Index = iIndex++;
      miCurr.Text = "&Beenden";
      miCurr.Click += new System.EventHandler (ExitClick);
      cm.MenuItems.Add (miCurr);

      // NotifyIcon selbst erzeugen
      notico = new NotifyIcon ();
      notico.Icon = new Icon("smile.ico"); // Eigenes Icon einsetzen
      notico.Text = "Doppelklick mich!";   // Eigenen Text einsetzen
      notico.Visible = true;
      notico.ContextMenu = cm;
      notico.DoubleClick += new EventHandler (NotifyIconDoubleClick);

      // Ohne Appplication.Run geht es nicht
      Application.Run ();
   }

   //==========================================================================
   private static void ExitClick (Object sender, EventArgs e)
   {
      notico.Dispose ();
      Application.Exit ();
   }

   //==========================================================================
   private static void Action1Click (Object sender, EventArgs e)
   {
      // nur als Beispiel:
      // new MyForm ().Show ();
   }

   //==========================================================================
   private static void NotifyIconDoubleClick (Object sender, EventArgs e)
   {
      // Was immer du willst
   }
}
Sie haben Fragen zu diesem Snippet oder brauchen Hilfe bei der .NET Entwicklung?
Freundliche und kompetente Entwickler helfen Ihnen gern weiter im Forum für .NET Entwicklung.



Kommentare:
(Zum Schreiben von Kommentaren bitte anmelden.)



schlecht sehr gut
1 2 3 4 5 6 7 8 9 10
Nur angemeldete User können Snippets bewerten.