예제 #1
0
        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);
            }
        }
예제 #2
0
 public void Dispose()
 {
     if (_notifyIcon != null)
     {
         _notifyIcon.Dispose();
         _notifyIcon = null;
     }
 }
예제 #3
0
        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);
                }
            });
        }
예제 #4
0
        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);
            }
        }
예제 #5
0
        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);
            }
        }
예제 #6
0
        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();
        }
예제 #7
0
        // 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);
                    }
                }
            }
        }
예제 #8
0
 /// <summary>
 /// Initializes the class.
 /// </summary>
 public override void Initialize()
 {
     this.notifyIcon = new NotificationAreaIcon();
 }