NotifyIcon NotifyIcon NotifyIcon NotifyIcon Class

Definizione

Specifica un componente che crea un'icona nell'area di notifica.Specifies a component that creates an icon in the notification area. Questa classe non può essere ereditata.This class cannot be inherited.

public ref class NotifyIcon sealed : System::ComponentModel::Component
public sealed class NotifyIcon : System.ComponentModel.Component
type NotifyIcon = class
    inherit Component
Public NotInheritable Class NotifyIcon
Inherits Component
Ereditarietà

Esempi

Esempio di codice seguente illustra l'uso di NotifyIcon classe per visualizzare un'icona per un'applicazione nell'area di notifica.The following code example demonstrates using the NotifyIcon class to display an icon for an application in the notification area. Nell'esempio viene illustrato come impostare il Icon, ContextMenu, Text, e Visible le proprietà e la gestione il DoubleClick evento.The example demonstrates setting the Icon, ContextMenu, Text, and Visible properties and handling the DoubleClick event. Oggetto ContextMenu con un Exit elemento su di esso viene assegnato al NotifyIcon.ContextMenu proprietà, che consente di chiudere l'applicazione.A ContextMenu with an Exit item on it is assigned to the NotifyIcon.ContextMenu property, which allows the user to close the application. Quando la DoubleClick si verifica l'evento, il modulo viene attivato chiamando la Form.Activate (metodo).When the DoubleClick event occurs, the application form is activated by calling the Form.Activate method.

#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
public ref class Form1: public System::Windows::Forms::Form
{
private:
   System::Windows::Forms::NotifyIcon^ notifyIcon1;
   System::Windows::Forms::ContextMenu^ contextMenu1;
   System::Windows::Forms::MenuItem^ menuItem1;
   System::ComponentModel::IContainer^ components;

public:
   Form1()
   {
      this->components = gcnew System::ComponentModel::Container;
      this->contextMenu1 = gcnew System::Windows::Forms::ContextMenu;
      this->menuItem1 = gcnew System::Windows::Forms::MenuItem;
      
      // Initialize contextMenu1
      array<System::Windows::Forms::MenuItem^>^temp0 = {this->menuItem1};
      this->contextMenu1->MenuItems->AddRange( temp0 );
      
      // Initialize menuItem1
      this->menuItem1->Index = 0;
      this->menuItem1->Text = "E&xit";
      this->menuItem1->Click += gcnew System::EventHandler( this, &Form1::menuItem1_Click );
      
      // Set up how the form should be displayed.
      this->ClientSize = System::Drawing::Size( 292, 266 );
      this->Text = "Notify Icon Example";
      
      // Create the NotifyIcon.
      this->notifyIcon1 = gcnew System::Windows::Forms::NotifyIcon( this->components );
      
      // The Icon property sets the icon that will appear
      // in the systray for this application.
      notifyIcon1->Icon = gcnew System::Drawing::Icon( "appicon.ico" );
      
      // The ContextMenu property sets the menu that will
      // appear when the systray icon is right clicked.
      notifyIcon1->ContextMenu = this->contextMenu1;
      
      // The Text property sets the text that will be displayed,
      // in a tooltip, when the mouse hovers over the systray icon.
      notifyIcon1->Text = "Form1 (NotifyIcon example)";
      notifyIcon1->Visible = true;
      
      // Handle the DoubleClick event to activate the form.
      notifyIcon1->DoubleClick += gcnew System::EventHandler( this, &Form1::notifyIcon1_DoubleClick );
   }

protected:
   ~Form1()
   {
      if ( components != nullptr )
      {
         delete components;
      }
   }

private:
   void notifyIcon1_DoubleClick( Object^ /*Sender*/, EventArgs^ /*e*/ )
   {
      
      // Show the form when the user double clicks on the notify icon.
      // Set the WindowState to normal if the form is minimized.
      if ( this->WindowState == FormWindowState::Minimized )
            this->WindowState = FormWindowState::Normal;
      
      // Activate the form.
      this->Activate();
   }

   void menuItem1_Click( Object^ /*Sender*/, EventArgs^ /*e*/ )
   {
      
      // Close the form, which closes the application.
      this->Close();
   }

};

[STAThread]
int main()
{
   Application::Run( gcnew Form1 );
}
using System;
using System.Drawing;
using System.Windows.Forms;

public class Form1 : System.Windows.Forms.Form
{
    private System.Windows.Forms.NotifyIcon notifyIcon1;
    private System.Windows.Forms.ContextMenu contextMenu1;
    private System.Windows.Forms.MenuItem menuItem1;
    private System.ComponentModel.IContainer components;

    [STAThread]
    static void Main() 
    {
        Application.Run(new Form1());
    }

    public Form1()
    {
        this.components = new System.ComponentModel.Container();
        this.contextMenu1 = new System.Windows.Forms.ContextMenu();
        this.menuItem1 = new System.Windows.Forms.MenuItem();

        // Initialize contextMenu1
        this.contextMenu1.MenuItems.AddRange(
                    new System.Windows.Forms.MenuItem[] {this.menuItem1});

        // Initialize menuItem1
        this.menuItem1.Index = 0;
        this.menuItem1.Text = "E&xit";
        this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);

        // Set up how the form should be displayed.
        this.ClientSize = new System.Drawing.Size(292, 266);
        this.Text = "Notify Icon Example";

        // Create the NotifyIcon.
        this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);

        // The Icon property sets the icon that will appear
        // in the systray for this application.
        notifyIcon1.Icon = new Icon("appicon.ico");

        // The ContextMenu property sets the menu that will
        // appear when the systray icon is right clicked.
        notifyIcon1.ContextMenu = this.contextMenu1;

        // The Text property sets the text that will be displayed,
        // in a tooltip, when the mouse hovers over the systray icon.
        notifyIcon1.Text = "Form1 (NotifyIcon example)";
        notifyIcon1.Visible = true;

        // Handle the DoubleClick event to activate the form.
        notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick);

    }

    protected override void Dispose( bool disposing )
    {
        // Clean up any components being used.
        if( disposing )
            if (components != null)
                components.Dispose();            

        base.Dispose( disposing );
    }

    private void notifyIcon1_DoubleClick(object Sender, EventArgs e) 
    {
        // Show the form when the user double clicks on the notify icon.

        // Set the WindowState to normal if the form is minimized.
        if (this.WindowState == FormWindowState.Minimized)
            this.WindowState = FormWindowState.Normal;

        // Activate the form.
        this.Activate();
    }

    private void menuItem1_Click(object Sender, EventArgs e) {
        // Close the form, which closes the application.
        this.Close();
    }
}
Imports System
Imports System.Drawing
Imports System.Windows.Forms

Public NotInheritable Class Form1
    Inherits System.Windows.Forms.Form

    Private contextMenu1 As System.Windows.Forms.ContextMenu
    Friend WithEvents menuItem1 As System.Windows.Forms.MenuItem
    Friend WithEvents notifyIcon1 As System.Windows.Forms.NotifyIcon
    Private components As System.ComponentModel.IContainer

    <System.STAThread()> _
    Public Shared Sub Main()
        System.Windows.Forms.Application.Run(New Form1)
    End Sub 'Main

    Public Sub New()

        Me.components = New System.ComponentModel.Container
        Me.contextMenu1 = New System.Windows.Forms.ContextMenu
        Me.menuItem1 = New System.Windows.Forms.MenuItem

        ' Initialize contextMenu1
        Me.contextMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() _
                            {Me.menuItem1})

        ' Initialize menuItem1
        Me.menuItem1.Index = 0
        Me.menuItem1.Text = "E&xit"

        ' Set up how the form should be displayed.
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Text = "Notify Icon Example"

        ' Create the NotifyIcon.
        Me.notifyIcon1 = New System.Windows.Forms.NotifyIcon(Me.components)

        ' The Icon property sets the icon that will appear
        ' in the systray for this application.
        notifyIcon1.Icon = New Icon("appicon.ico")

        ' The ContextMenu property sets the menu that will
        ' appear when the systray icon is right clicked.
        notifyIcon1.ContextMenu = Me.contextMenu1

        ' The Text property sets the text that will be displayed,
        ' in a tooltip, when the mouse hovers over the systray icon.
        notifyIcon1.Text = "Form1 (NotifyIcon example)"
        notifyIcon1.Visible = True
    End Sub 'New
    
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        ' Clean up any components being used.
        If disposing Then
            If (components IsNot Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub 'Dispose

    Private Sub notifyIcon1_DoubleClick(Sender as object, e as EventArgs) handles notifyIcon1.DoubleClick
        ' Show the form when the user double clicks on the notify icon.

        ' Set the WindowState to normal if the form is minimized.
        if (me.WindowState = FormWindowState.Minimized) then _
            me.WindowState = FormWindowState.Normal

        ' Activate the form.
        me.Activate()
    end sub

    Private Sub menuItem1_Click(Sender as object, e as EventArgs) handles menuItem1.Click
        ' Close the form, which closes the application.
        me.Close()
    end sub

End Class 'Form1

Commenti

Le icone nell'area di notifica sono collegamenti ai processi in esecuzione in background di un computer, ad esempio un'applicazione antivirus o un controllo del volume.Icons in the notification area are shortcuts to processes that are running in the background of a computer, such as a virus protection program or a volume control. Questi processi non vengono forniti con le proprie interfacce utente.These processes do not come with their own user interfaces. Il NotifyIcon classe fornisce un modo per prevedere questa funzionalità.The NotifyIcon class provides a way to program in this functionality. Il Icon proprietà definisce l'icona visualizzata nell'area di notifica.The Icon property defines the icon that appears in the notification area. Menu di scelta rapida per un'icona vengano risolti con le ContextMenu proprietà.Pop-up menus for an icon are addressed with the ContextMenu property. Il Text proprietà assegna il testo della descrizione comando.The Text property assigns ToolTip text. Affinché l'icona da visualizzare nell'area di notifica, il Visible proprietà deve essere impostata su true.In order for the icon to show up in the notification area, the Visible property must be set to true.

Costruttori

NotifyIcon() NotifyIcon() NotifyIcon() NotifyIcon()

Inizializza una nuova istanza della classe NotifyIcon.Initializes a new instance of the NotifyIcon class.

NotifyIcon(IContainer) NotifyIcon(IContainer) NotifyIcon(IContainer) NotifyIcon(IContainer)

Inizializza una nuova istanza della classe NotifyIcon con il contenitore specificato.Initializes a new instance of the NotifyIcon class with the specified container.

Proprietà

BalloonTipIcon BalloonTipIcon BalloonTipIcon BalloonTipIcon

Ottiene o imposta l'icona da visualizzare sul fumetto suggerimento associato a NotifyIcon.Gets or sets the icon to display on the balloon tip associated with the NotifyIcon.

BalloonTipText BalloonTipText BalloonTipText BalloonTipText

Ottiene o imposta il testo da visualizzare sul fumetto suggerimento associato a NotifyIcon.Gets or sets the text to display on the balloon tip associated with the NotifyIcon.

BalloonTipTitle BalloonTipTitle BalloonTipTitle BalloonTipTitle

Ottiene o imposta il titolo del suggerimento visualizzato su NotifyIcon.Gets or sets the title of the balloon tip displayed on the NotifyIcon.

CanRaiseEvents CanRaiseEvents CanRaiseEvents CanRaiseEvents

Ottiene un valore che indica se il componente può generare un evento.Gets a value indicating whether the component can raise an event.

(Inherited from Component)
Container Container Container Container

Ottiene il IContainer che contiene il Component.Gets the IContainer that contains the Component.

(Inherited from Component)
ContextMenu ContextMenu ContextMenu ContextMenu

Ottiene o imposta il menu di scelta rapida dell'icona.Gets or sets the shortcut menu for the icon.

ContextMenuStrip ContextMenuStrip ContextMenuStrip ContextMenuStrip

Ottiene o imposta il menu di scelta rapida associato all'oggetto NotifyIcon.Gets or sets the shortcut menu associated with the NotifyIcon.

DesignMode DesignMode DesignMode DesignMode

Ottiene un valore che indica se il Component si trova in modalità progettazione.Gets a value that indicates whether the Component is currently in design mode.

(Inherited from Component)
Events Events Events Events

Ottiene l'elenco dei gestori eventi allegati a questo Component.Gets the list of event handlers that are attached to this Component.

(Inherited from Component)
Icon Icon Icon Icon

Ottiene o imposta l'icona corrente.Gets or sets the current icon.

Site Site Site Site

Ottiene o imposta l'oggetto ISite di Component.Gets or sets the ISite of the Component.

(Inherited from Component)
Tag Tag Tag Tag

Ottiene o imposta un oggetto che contiene i dati relativi all'oggetto NotifyIcon.Gets or sets an object that contains data about the NotifyIcon.

Text Text Text Text

Ottiene o imposta il testo della descrizione comando visualizzato quando il puntatore del mouse viene posizionato su un'icona dell'area di notifica.Gets or sets the ToolTip text displayed when the mouse pointer rests on a notification area icon.

Visible Visible Visible Visible

Ottiene o imposta un valore che indica se l'icona è visibile nell'area di notifica della barra delle applicazioni.Gets or sets a value indicating whether the icon is visible in the notification area of the taskbar.

Metodi

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

Consente di creare un oggetto che contiene tutte le informazioni rilevanti necessarie per la generazione del proxy utilizzato per effettuare la comunicazione con un oggetto remoto.Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose() Dispose() Dispose() Dispose()

Rilascia tutte le risorse usate da Component.Releases all resources used by the Component.

(Inherited from Component)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

Rilascia le risorse non gestite usate da Component e, facoltativamente, le risorse gestite.Releases the unmanaged resources used by the Component and optionally releases the managed resources.

(Inherited from Component)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Funge da funzione hash predefinita.Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

Consente di recuperare l'oggetto servizio di durata corrente per controllare i criteri di durata per l'istanza.Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetService(Type) GetService(Type) GetService(Type) GetService(Type)

Consente di restituire un oggetto che rappresenta un servizio fornito da Component o dal relativo Container.Returns an object that represents a service provided by the Component or by its Container.

(Inherited from Component)
GetType() GetType() GetType() GetType()

Ottiene l'oggetto Type dell'istanza corrente.Gets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

Ottiene un oggetto servizio di durata per controllare i criteri di durata per questa istanza.Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

Crea una copia dei riferimenti dell'oggetto MarshalByRefObject corrente.Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
ShowBalloonTip(Int32) ShowBalloonTip(Int32) ShowBalloonTip(Int32) ShowBalloonTip(Int32)

Visualizza un fumetto suggerimento nella barra delle applicazioni per il periodo di tempo specificato.Displays a balloon tip in the taskbar for the specified time period.

ShowBalloonTip(Int32, String, String, ToolTipIcon) ShowBalloonTip(Int32, String, String, ToolTipIcon) ShowBalloonTip(Int32, String, String, ToolTipIcon) ShowBalloonTip(Int32, String, String, ToolTipIcon)

Visualizza un fumetto suggerimento con il titolo, il testo e l'icona specificati nella barra delle applicazioni per il periodo di tempo specificato.Displays a balloon tip with the specified title, text, and icon in the taskbar for the specified time period.

ToString() ToString() ToString() ToString()

Restituisce un oggetto String che contiene il nome dell'eventuale oggetto Component.Returns a String containing the name of the Component, if any. Questo metodo non deve essere sottoposto a override.This method should not be overridden.

(Inherited from Component)

Eventi

BalloonTipClicked BalloonTipClicked BalloonTipClicked BalloonTipClicked

Si verifica quando si fa clic sul fumetto suggerimento.Occurs when the balloon tip is clicked.

BalloonTipClosed BalloonTipClosed BalloonTipClosed BalloonTipClosed

Si verifica quando il fumetto suggerimento viene chiuso dall'utente.Occurs when the balloon tip is closed by the user.

BalloonTipShown BalloonTipShown BalloonTipShown BalloonTipShown

Si verifica quando viene visualizzato il fumetto suggerimento sullo schermo.Occurs when the balloon tip is displayed on the screen.

Click Click Click Click

Si verifica quando l'utente fa clic sull'icona nell'area di notifica.Occurs when the user clicks the icon in the notification area.

Disposed Disposed Disposed Disposed

Si verifica quando il componente viene eliminato da una chiamata al metodo Dispose().Occurs when the component is disposed by a call to the Dispose() method.

(Inherited from Component)
DoubleClick DoubleClick DoubleClick DoubleClick

Si verifica quando l'utente fa doppio clic sull'icona nell'area di notifica della barra delle applicazioni.Occurs when the user double-clicks the icon in the notification area of the taskbar.

MouseClick MouseClick MouseClick MouseClick

Si verifica quando l'utente fa clic su un oggetto NotifyIcon con il mouse.Occurs when the user clicks a NotifyIcon with the mouse.

MouseDoubleClick MouseDoubleClick MouseDoubleClick MouseDoubleClick

Si verifica quando l'utente fa doppio clic su un oggetto NotifyIcon con il mouse.Occurs when the user double-clicks the NotifyIcon with the mouse.

MouseDown MouseDown MouseDown MouseDown

Si verifica quando l'utente preme il pulsante del mouse mentre il puntatore è posizionato sull'icona nell'area di notifica della barra delle applicazioni.Occurs when the user presses the mouse button while the pointer is over the icon in the notification area of the taskbar.

MouseMove MouseMove MouseMove MouseMove

Si verifica quando sposta il mouse mentre il puntatore è posizionato sull'icona nell'area di notifica della barra delle applicazioni.Occurs when the user moves the mouse while the pointer is over the icon in the notification area of the taskbar.

MouseUp MouseUp MouseUp MouseUp

Si verifica quando l'utente rilascia il pulsante del mouse mentre il puntatore è posizionato sull'icona nell'area di notifica della barra delle applicazioni.Occurs when the user releases the mouse button while the pointer is over the icon in the notification area of the taskbar.

Sicurezza

UIPermission
Per creare il NotifyIcon componente.to create the NotifyIcon component. Enumerazione associata: AllWindowsAssociated enumeration: AllWindows

Si applica a