locked
What is wrong with my code? (This is a C# Small Basic Extension) RRS feed

  • Question

  • Here is my code:
    [SmallBasicType]
    	public static class PlusPlusTaskbar
    	{
    
    		static NotifyIcon notifyicon = new NotifyIcon();
    
    		/// <summary>
    		/// Shows a notification balloon on the notification area.</summary>
    		/// <param name="Icon">The full file path of the notification area icon.</param>
    		/// <param name="TipTitle">The title of the balloon.</param>
    		/// <param name="TipText">The message displayed in the balloon.</param>
    		/// <param name="TipIcon">The icon of the balloon (can be "Info", "Warning", "Error" or "None").</param>
    		/// <param name="TimeOut">The amount of time to display the dialog (excludes time during which it is detected that the user is not actively using the computer).</param>
    		/// <returns>Nothing.</returns>
    		public static void ShowNotification(Primitive Icon, Primitive TipTitle, Primitive TipText, Primitive TipIcon, Primitive TimeOut)
    		{
    			if (Icon == "Info")
    			{
    				notifyicon.Icon = new Icon(Icon);
    				notifyicon.BalloonTipIcon = ToolTipIcon.Info;
    				notifyicon.BalloonTipText = TipText;
    				notifyicon.BalloonTipTitle = TipTitle;
    				notifyicon.Visible = true;
    				notifyicon.ShowBalloonTip(TimeOut, TipTitle, TipText, ToolTipIcon.Info);
    			}
    			else if (Icon == "Error")
    			{
    				notifyicon.Icon = new Icon(Icon);
    				notifyicon.BalloonTipIcon = ToolTipIcon.Error;
    				notifyicon.BalloonTipText = TipText;
    				notifyicon.BalloonTipTitle = TipTitle;
    				notifyicon.Visible = true;
    				notifyicon.ShowBalloonTip(TimeOut, TipTitle, TipText, ToolTipIcon.Error);
    			}
    			else if (Icon == "Warning")
    			{
    				notifyicon.Icon = new Icon(Icon);
    				notifyicon.BalloonTipIcon = ToolTipIcon.Warning;
    				notifyicon.BalloonTipText = TipText;
    				notifyicon.BalloonTipTitle = TipTitle;
    				notifyicon.Visible = true;
    				notifyicon.ShowBalloonTip(TimeOut, TipTitle, TipText, ToolTipIcon.Warning);
    			}
    			else
    			{
    				notifyicon.Icon = new Icon(Icon);
    				notifyicon.BalloonTipIcon = ToolTipIcon.None;
    				notifyicon.BalloonTipText = TipText;
    				notifyicon.BalloonTipTitle = TipTitle;
    				notifyicon.Visible = true;
    				notifyicon.ShowBalloonTip(TimeOut);
    			}
    		}
    
    		// This is the SmallBasic delegate
    		private static SmallBasicCallback _IconClickDelegate;
    
    		// Event subroutine calls the SmallBasic delegate 
    		private static void _IconClickEvent(Object sender, EventArgs e)
    		{
    			_IconClickDelegate();
    		}
    
    		// Start event and set SmallBasic callback delegate
    		private static SmallBasicCallback _IconClick
    		{
    			get
    			{
    				return _IconClickDelegate;
    			}
    			set
    			{
    				_IconClickDelegate = value;
    				notifyicon.Click += new System.EventHandler(_IconClickEvent);
    			}
    		}
    
    		/// <summary>
    		/// Event when the icon is clicked (is currently not working).
    		/// </summary>
    		public static event SmallBasicCallback IconClick
    		{
    			add
    			{
    				_IconClick = null;
    				_IconClick = (SmallBasicCallback)Delegate.Combine(_IconClick, value);
    			}
    			remove
    			{
    				_IconClick = (SmallBasicCallback)Delegate.Remove(_IconClick, value);
    			}
    		}
    
    		// This is the SmallBasic delegate
    		private static SmallBasicCallback _IconDoubleClickDelegate;
    
    		// Event subroutine calls the SmallBasic delegate 
    		private static void _IconDoubleClickEvent(Object sender, EventArgs e)
    		{
    			_IconDoubleClickDelegate();
    		}
    
    		// Start event and set SmallBasic callback delegate
    		private static SmallBasicCallback _IconDoubleClick
    		{
    			get
    			{
    				return _IconDoubleClickDelegate;
    			}
    			set
    			{
    				_IconDoubleClickDelegate = value;
    				notifyicon.DoubleClick += new System.EventHandler(_IconDoubleClickEvent);
    			}
    		}
    
    		/// <summary>
    		/// Event when the icon is double clicked (is currently not working).
    		/// </summary>
    		public static event SmallBasicCallback IconDoubleClick
    		{
    			add
    			{
    				_IconDoubleClick = null;
    				_IconDoubleClick = (SmallBasicCallback)Delegate.Combine(_IconDoubleClick, value);
    			}
    			remove
    			{
    				_IconDoubleClick = (SmallBasicCallback)Delegate.Remove(_IconDoubleClick, value);
    			}
    		}
    
    
    	}
    The events show up in Small Basic, but fail to fire when the user clicks on the tray icon? Any ideas?
    Wednesday, April 18, 2012 12:36 AM
    Answerer

Answers

  • I would recommend writing a test C# program with a form that displays an icon in the notification area to test and able to debug first.  Then try attaching to events on non-form icons you didn't create, getting events from these is another whole ballgame.  Write the simple debuggable program and then probably ask followups in a C# forum.  When it works in an forms app, then transfer the ideas to an extension.
    • Marked as answer by gungan37Editor Wednesday, April 18, 2012 10:27 PM
    Wednesday, April 18, 2012 9:02 PM

All replies

  • I would recommend writing a test C# program with a form that displays an icon in the notification area to test and able to debug first.  Then try attaching to events on non-form icons you didn't create, getting events from these is another whole ballgame.  Write the simple debuggable program and then probably ask followups in a C# forum.  When it works in an forms app, then transfer the ideas to an extension.
    • Marked as answer by gungan37Editor Wednesday, April 18, 2012 10:27 PM
    Wednesday, April 18, 2012 9:02 PM
  • Thanks! I will do exactly that. I appreciate your help, LitDev.
    Wednesday, April 18, 2012 10:27 PM
    Answerer