Este artigo foi traduzido por máquina. Coloque o ponteiro do mouse sobre as frases do artigo para ver o texto original. Mais informações. |
Tradução
Original
|
Classe NotifyIcon
Especifica um componente que cria um ícone na área de notificação. Esta classe não pode ser herdada.
Assembly: System.Windows.Forms (em System.Windows.Forms.dll)
Ícones na área de notificação são atalhos para os processos que são Executando no plano de fundo de um computador, como um programa de proteção contra vírus ou um Controle de volume. Esses processos não vêm com suas próprias interfaces do usuário. The NotifyIcon classe fornece uma maneira de programa nessa funcionalidade. The Icon propriedade define o ícone que aparece na área de notificação. Menus pop-up para um ícone são tratadas com o ContextMenu propriedade. A propriedade Text atribui o texto de dica de ferramenta. Para que o ícone para mostrar na área de notificação, a Visible propriedade deve ser conjunto para true.
O exemplo de código a seguir demonstra o uso da classe NotifyIcon para exibir um ícone para um aplicativo na área de notificação. O exemplo demonstra a Configuração das propriedades Icon, ContextMenu, Text e Visible e manipular o evento DoubleClick. Um ContextMenu com um item Sair é atribuído para a propriedade NotifyIconContextMenu, que permite que o usuário feche o aplicativo. Quando o evento DoubleClick ocorre, o formulário do aplicativo é ativado, chamando o método FormActivate.
using System; using System.Drawing; using System.Windows.Forms; publicclass 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] staticvoid 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 contextMenu1this.contextMenu1.MenuItems.AddRange( new System.Windows.Forms.MenuItem[] {this.menuItem1}); // Initialize menuItem1this.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); } protectedoverridevoid Dispose( bool disposing ) { // Clean up any components being used.if( disposing ) if (components != null) components.Dispose(); base.Dispose( disposing ); } privatevoid 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(); } privatevoid menuItem1_Click(object Sender, EventArgs e) { // Close the form, which closes the application.this.Close(); } }
import System.*;
import System.Drawing.*;
import System.Windows.Forms.*;
public class Form1 extends 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;
/** @attribute STAThread()
*/
public static void main(String[] args)
{
Application.Run(new Form1());
} //main
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.get_MenuItems().AddRange(
new System.Windows.Forms.MenuItem[] { this.menuItem1 });
// Initialize menuItem1
this.menuItem1.set_Index(0);
this.menuItem1.set_Text("E&xit");
this.menuItem1.add_Click(new System.EventHandler(this.menuItem1_Click));
// Set up how the form should be displayed.
this.set_ClientSize(new System.Drawing.Size(292, 266));
this.set_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.set_Icon(new Icon("appicon.ico"));
// The ContextMenu property sets the menu that will
// appear when the systray icon is right clicked.
notifyIcon1.set_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.set_Text("Form1 (NotifyIcon example)");
notifyIcon1.set_Visible(true);
// Handle the DoubleClick event to activate the form.
notifyIcon1.add_DoubleClick(
new System.EventHandler(this.notifyIcon1_DoubleClick));
} //Form1
protected void Dispose(boolean disposing)
{
// Clean up any components being used.
if (disposing) {
if (components != null) {
components.Dispose();
}
}
super.Dispose(disposing);
} //Dispose
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.get_WindowState().Equals(FormWindowState.Minimized)) {
this.set_WindowState(FormWindowState.Normal);
}
// Activate the form.
this.Activate();
} //notifyIcon1_DoubleClick
private void menuItem1_Click(Object Sender, EventArgs e)
{
// Close the form, which closes the application.
this.Close();
} //menuItem1_Click
} //Form1
-
UIPermission
para criar o componente NotifyIcon.Enumeração associada: UIPermissionWindow.AllWindows
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.NotifyIcon
Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
o.NET Framework e.NET Compact Framework não oferecem suporte a todas as versões de cada plataforma. Para obter uma lista de versões suportadas, consulte Requisitos de sistema do .NET framework.