<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Martijn's C# Programming Blog &#187; StatusIcon</title>
	<atom:link href="http://www.dijksterhuis.org/tag/statusicon/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dijksterhuis.org</link>
	<description>Information, news about programming in C#</description>
	<lastBuildDate>Fri, 07 Aug 2009 21:26:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Creating a GTK notification area icon using Mono and C#</title>
		<link>http://www.dijksterhuis.org/creating-gtk-notification-area-icon-mono/</link>
		<comments>http://www.dijksterhuis.org/creating-gtk-notification-area-icon-mono/#comments</comments>
		<pubDate>Fri, 02 Jan 2009 08:14:59 +0000</pubDate>
		<dc:creator>Martijn</dc:creator>
				<category><![CDATA[Beginner]]></category>
		<category><![CDATA[GTK]]></category>
		<category><![CDATA[Learn C#]]></category>
		<category><![CDATA[mono]]></category>
		<category><![CDATA[StatusIcon]]></category>
		<category><![CDATA[Tooltip]]></category>

		<guid isPermaLink="false">http://www.dijksterhuis.org/?p=435</guid>
		<description><![CDATA[
Cool (Linux) applications have their own icon in the notification area. To add my own icon in the Gnome notification area using Mono only took a few lines of code. In the post below I show how you can add your icon and associate a tooltip and right click menu to it.

GTK provides the StatusIcon [...]<p>This is a post from <a href="http://www.dijksterhuis.org">Martijn's C# Coding Blog</a>. </p>
]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.dijksterhuis.org/wp-content/uploads/2009/01/tooltip.png"><img src="http://www.dijksterhuis.org/wp-content/uploads/2009/01/tooltip.png" alt="Adding a Gnome tooltip to your application with C# and Mono" title="Adding a Gnome tooltip to your application with C# and Mono" width="500" height="57" class="alignnone size-full wp-image-436" /></a></p>
<p><em>Cool (Linux) applications have their own icon in the notification area. To add my own icon in the Gnome notification area using Mono only took a few lines of code. In the post below I show how you can add your icon and associate a tooltip and right click menu to it.</em></p>
<p><span id="more-435"></span></p>
<p>GTK provides the <em>StatusIcon</em> class to register your own icon in the notification area.</p>
<pre class="brush: c#">
    StatusIcon  myStatusIcon;
</pre>
<p>You can provide and load your own icon, but for this example I used one of the GTK stock icons.</p>
<pre class="brush: c#">
     myStatusIcon = StatusIcon.NewFromStock(Stock.Harddisk);  // I use a stock icon from Stock.*
                                                                                          // to avoid having to include an icon file
     myStatusIcon.Visible = true;                                             // Make sure we are displayed
</pre>
<p>Adding or changing a tooltip is as straighforward as assigning it:</p>
<pre class="brush: c#">
      myStatusIcon.Tooltip = &quot;Hello World ToolTip&quot;;                      // The message to show when the mouse hovers over the icon
</pre>
<p>To create a rightclick menu we need to register the PopupMenu event handler:</p>
<pre class="brush: c#">
     myStatusIcon.PopupMenu += OnStatusIconPopupMenu;         // Link in the right click popup menu
     ...
     ...

    /* The Status Popup menu is shown when the user right clicks on the toolbar icon */

    protected void OnStatusIconPopupMenu(object sender, EventArgs e)
    {
        Menu popupMenu = new Menu();

        MenuItem helloItem = new MenuItem(&quot;About Hello World&quot;);
        helloItem.Show();
        helloItem.Activated += new EventHandler(OnHelloAboutActivated);

        popupMenu.Append(helloItem);
        popupMenu.Popup(null,null,null,3,Gtk.Global.CurrentEventTime);
    }
</pre>
<p>And that is really all there is to it. I have included the complete code below. If you create a new GTK solution in MonoDevelop you will end up with two files, Main.cs and MainWindows.Cs. Replace the MainWindow.CS file with the content below: </p>
<pre class="brush: c#">

using System;
using Gtk;

public partial class MainWindow: Gtk.Window
{
	StatusIcon  myStatusIcon;
	AboutDialog aboutDialog;

	public MainWindow (): base (Gtk.WindowType.Toplevel)
	{

		/* The following lines create the notification area status icon */
		/* Make it visible and link in the right click popup menu       */ 

		myStatusIcon = StatusIcon.NewFromStock(Stock.Harddisk);  // I use a stock icon from Stock.*
		                                                         // to avoid having to include an icon file
		myStatusIcon.Tooltip = &quot;Hello World ToolTip&quot;;            // The message to show when the mouse hovers over the icon
		myStatusIcon.Visible = true;                             // Make sure we are displayed
		myStatusIcon.PopupMenu += OnStatusIconPopupMenu;         // Link in the right click popup menu 

		/* Not necessary */
		Label AppWindowLabel = new Label(&quot;Hello World&quot;);
		this.Add(AppWindowLabel);

		Build ();
	}

	/* Called when the main application closes */

	protected void OnDeleteEvent (object sender, DeleteEventArgs a)
	{
		Application.Quit ();
		a.RetVal = true;
	}

	/* The Status Popup menu is shown when the user right clicks on the toolbar icon */

	protected void OnStatusIconPopupMenu(object sender, EventArgs e)
	{
		Menu popupMenu = new Menu();

		MenuItem helloItem = new MenuItem(&quot;About Hello World&quot;);
		helloItem.Show();
		helloItem.Activated += new EventHandler(OnHelloAboutActivated);

		popupMenu.Append(helloItem);
		popupMenu.Popup(null,null,null,3,Gtk.Global.CurrentEventTime);
	}

	/* If the user select the &quot;About Hello World&quot; menu option, we show the about dialog */

	protected void OnHelloAboutActivated(object sender, EventArgs e)
	{
		aboutDialog = new AboutDialog();

		aboutDialog.ProgramName = &quot;The About Dialog Popup Demo&quot;;
		aboutDialog.Version = &quot;1.0beta&quot;;
		aboutDialog.Comments = &quot;The best things in life are simple!&quot;;
		aboutDialog.License = &quot;Creative Commons&quot;;
		aboutDialog.Authors = new string[] { &quot;Martijn Dijksterhuis&quot; };
		aboutDialog.Website = &quot;http://www.dijksterhuis.org&quot;;
		aboutDialog.Response += new ResponseHandler(OnHelloAboutClose);

		aboutDialog.Run();
	}

	/* Catch the &quot;Close&quot; and &quot;X&quot; button event from the about dialog box */

	protected void OnHelloAboutClose(object sender, ResponseArgs e)
	{
		if (e.ResponseId==ResponseType.Cancel || e.ResponseId==ResponseType.DeleteEvent)
		 aboutDialog.Destroy();
	}

}
</pre>
<p>This is a post from <a href="http://www.dijksterhuis.org">Martijn's C# Coding Blog</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.dijksterhuis.org/creating-gtk-notification-area-icon-mono/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
