visual usar tiempo real notificaciones notificacion net iconos asp agregar c# .net winforms notifyicon notification-area

tiempo - usar notifyicon c#



Mostrar una notificación de globo (5)

Estoy tratando de usar el siguiente código para mostrar una notificación de globo. He verificado que se está ejecutando mediante el uso de puntos de interrupción. Tampoco está mostrando errores.

¿Qué debo hacer para depurar esto, ya que no se producen errores y no se muestra el globo?

private void showBalloon(string title, string body) { NotifyIcon notifyIcon = new NotifyIcon(); notifyIcon.Visible = true; if (title != null) { notifyIcon.BalloonTipTitle = title; } if (body != null) { notifyIcon.BalloonTipText = body; } notifyIcon.ShowBalloonTip(30000); }


Matthew identificó el problema, pero todavía me costaba unir todas las piezas. Así que pensé que un ejemplo conciso que funciona en LINQPad as-is sería útil (y presumiblemente en otro lugar). Simplemente haga referencia al ensamblado System.Windows.Forms y pegue este código.

var notification = new System.Windows.Forms.NotifyIcon() { Visible = true, Icon = System.Drawing.SystemIcons.Information, // optional - BalloonTipIcon = System.Windows.Forms.ToolTipIcon.Info, // optional - BalloonTipTitle = "My Title", BalloonTipText = "My long description...", }; // Display for 5 seconds. notification.ShowBalloonTip(5000); // This will let the balloon close after it''s 5 second timeout // for demonstration purposes. Comment this out to see what happens // when dispose is called while a balloon is still visible. Thread.Sleep(10000); // The notification should be disposed when you don''t need it anymore, // but doing so will immediately close the balloon if it''s visible. notification.Dispose();


No ha especificado realmente un icono para mostrar en la barra de tareas. Ejecutando su código en LINQPad, simplemente agregando " notifyIcon.Icon = SystemIcons.Application antes de la llamada a ShowBalloonTip pude obtener la sugerencia que se mostrará. También tenga en cuenta que debe llamar a Dispose cuando haya terminado con su instancia de NotifyIcon .


ShowBalloonnTip toma el número de milisegundos. 3 milisegundos puede ser demasiado rápido para que incluso pueda ver. Pruebe algo más como 3000

Es posible que deba pasar un modelo de componente al contructor. Es lo que veo en todos los ejemplos. Lo siento, ha pasado mucho tiempo desde que lo he usado. Vea la primera respuesta aquí:

NotifyIcon no muestra



Vea el siguiente código fuente.

using System; using System.ComponentModel; using System.Drawing; using System.IO; using System.Reflection; using System.Windows.Forms; namespace ShowToolTip { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btBallonToolTip_Click(object sender, EventArgs e) { ShowBalloonTip(); this.Hide(); } private void ShowBalloonTip() { Container bpcomponents = new Container(); ContextMenu contextMenu1 = new ContextMenu(); MenuItem runMenu = new MenuItem(); runMenu.Index = 1; runMenu.Text = "Run..."; runMenu.Click += new EventHandler(runMenu_Click); MenuItem breakMenu = new MenuItem(); breakMenu.Index = 2; breakMenu.Text = "-------------"; MenuItem exitMenu = new MenuItem(); exitMenu.Index = 3; exitMenu.Text = "E&xit"; exitMenu.Click += new EventHandler(exitMenu_Click); // Initialize contextMenu1 contextMenu1.MenuItems.AddRange( new System.Windows.Forms.MenuItem[] { runMenu, breakMenu, exitMenu }); // Initialize menuItem1 this.ClientSize = new System.Drawing.Size(0, 0); this.Text = "Ballon Tootip Example"; // Create the NotifyIcon. NotifyIcon notifyIcon = new NotifyIcon(bpcomponents); // The Icon property sets the icon that will appear // in the systray for this application. string iconPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"/setup-icon.ico"; notifyIcon.Icon = new Icon(iconPath); // The ContextMenu property sets the menu that will // appear when the systray icon is right clicked. notifyIcon.ContextMenu = contextMenu1; notifyIcon.Visible = true; // The Text property sets the text that will be displayed, // in a tooltip, when the mouse hovers over the systray icon. notifyIcon.Text = "Morgan Tech Space BallonTip Running..."; notifyIcon.BalloonTipText = "Morgan Tech Space BallonTip Running..."; notifyIcon.BalloonTipTitle = "Morgan Tech Space"; notifyIcon.ShowBalloonTip(1000); } void exitMenu_Click(object sender, EventArgs e) { this.Close(); } void runMenu_Click(object sender, EventArgs e) { MessageBox.Show("BallonTip is Running...."); } } }