public void SerialCreateDestroy() { using (NotificationAreaIcon notificationAreaIcon1 = new NotificationAreaIcon(Guid.NewGuid())) { Icon icon1 = new Icon(TEST_ICON); notificationAreaIcon1.Icon = icon1.Handle; notificationAreaIcon1.ToolTip = $"This is test #1"; notificationAreaIcon1.ShowIcon(); using (NotificationAreaIcon notificationAreaIcon2 = new NotificationAreaIcon(Guid.NewGuid())) { Icon icon2 = new Icon(TEST_ICON); notificationAreaIcon1.Icon = icon2.Handle; notificationAreaIcon1.ToolTip = $"This is test #2"; notificationAreaIcon1.ShowIcon(); using (NotificationAreaIcon notificationAreaIcon3 = new NotificationAreaIcon(Guid.NewGuid())) { Icon icon3 = new Icon(TEST_ICON); notificationAreaIcon1.Icon = icon3.Handle; notificationAreaIcon1.ToolTip = $"This is test #2"; notificationAreaIcon1.ShowIcon(); Thread.Sleep(500); } Thread.Sleep(500); } Thread.Sleep(500); } }
public void Dispose() { if (_notifyIcon != null) { _notifyIcon.Dispose(); _notifyIcon = null; } }
public void ParallelCreateDestroy() { int runCount = 100; Parallel.For(0, runCount, run => { using (NotificationAreaIcon notificationAreaIcon = new NotificationAreaIcon(Guid.NewGuid())) { Icon icon = new Icon(TEST_ICON); notificationAreaIcon.Icon = icon.Handle; notificationAreaIcon.ToolTip = $"This is test #{run}"; notificationAreaIcon.ShowIcon(); Thread.Sleep(500); } }); }
public void IconProperty() { using (NotificationAreaIcon notificationAreaIcon = new NotificationAreaIcon(Guid.NewGuid())) { Icon icon = new Icon(TEST_ICON); notificationAreaIcon.Icon = icon.Handle; notificationAreaIcon.ToolTip = $"This is test"; notificationAreaIcon.ShowIcon(); Thread.Sleep(500); notificationAreaIcon.Icon = null; Thread.Sleep(500); icon = new Icon(TEST_ICON); notificationAreaIcon.Icon = null; Thread.Sleep(500); } }
public void ToolTipProperty() { using (NotificationAreaIcon notificationAreaIcon = new NotificationAreaIcon(Guid.NewGuid())) { Icon icon = new Icon(TEST_ICON); notificationAreaIcon.Icon = icon.Handle; notificationAreaIcon.ToolTip = $"This is short tooltip"; notificationAreaIcon.ShowIcon(); Thread.Sleep(500); notificationAreaIcon.ToolTip = null; Thread.Sleep(500); notificationAreaIcon.ToolTip = String.Empty; Thread.Sleep(500); notificationAreaIcon.ToolTip = "This is a really long\nmulti-line tool-tip that is tool long to fit the tool tip property\n. This should be truncated and not cause an error."; Thread.Sleep(500); } }
protected override void OnInitialized(EventArgs e) { base.OnInitialized(e); // Try to convert the Uid to a GUID, or create a new guid if (!Guid.TryParse(this.Uid, out _itemGuid)) { _itemGuid = Guid.NewGuid(); } // Create the Win32 Notification Area Icon _notifyIcon = new NotificationAreaIcon(_itemGuid) { ToolTip = this.ToolTip?.ToString(), Icon = this._icon?.Handle }; _notifyIcon.NotificationIconEventHandler += OnNotificationIconEvent; // Show the icon _notifyIcon.ShowIcon(); }
// Handle the display of the command menu, based on the event type protected void HandleCommandMenu(Wpf.EventType eventType, int cursorX, int cursorY) { if (ContextMenu != null) { // Should we if (ShouldShowCommandMenu(eventType)) { // Set the position of the menu ContextMenu.Placement = PlacementMode.AbsolutePoint; ContextMenu.HorizontalOffset = cursorX; ContextMenu.VerticalOffset = cursorY; ContextMenu.IsOpen = true; // Show the window HwndSource hwndSource = PresentationSource.FromVisual(ContextMenu) as HwndSource; if (hwndSource != null) { NotificationAreaIcon.SetForegroundWindow(hwndSource.Handle); } } } }
/// <summary> /// Initializes the class. /// </summary> public override void Initialize() { this.notifyIcon = new NotificationAreaIcon(); }