<?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>Steven Harms &#187; mono</title>
	<atom:link href="http://www.sharms.org/blog/tag/mono/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sharms.org/blog</link>
	<description>Life, Linux and Technology</description>
	<lastBuildDate>Sun, 28 Aug 2011 18:02:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Annoying people with code: A gentle introduction to C# and Mono Part 3: Creating a GUI (Graphical) Mono / C# Program</title>
		<link>http://www.sharms.org/blog/2009/07/creating-a-gui-graphical-mono-c-program/</link>
		<comments>http://www.sharms.org/blog/2009/07/creating-a-gui-graphical-mono-c-program/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 20:10:24 +0000</pubDate>
		<dc:creator>sharms</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[mono]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.sharms.org/blog/?p=528</guid>
		<description><![CDATA[In this post we will cover how to make a basic GUI application using Mono along with Monodevelop. If you haven&#8217;t already, you will want to read part 1 and part 2 of this series before this article. Monodevelop Monodevelop is the tool we are using as our editor. This is Linux&#8217;s equivalent of Visual [...]


Related posts:<ol><li><a href='http://www.sharms.org/blog/2009/07/annoying-people-with-code-a-gentle-introduction-to-c-and-mono/' rel='bookmark' title='Permanent Link: Annoying people with code: A gentle introduction to C# and Mono'>Annoying people with code: A gentle introduction to C# and Mono</a></li>
<li><a href='http://www.sharms.org/blog/2009/07/annoying-people-with-code-a-gentle-introduction-to-c-and-mono-part-2-data-types/' rel='bookmark' title='Permanent Link: Annoying people with code: A gentle introduction to C# and Mono Part 2 &#8211; Data Types'>Annoying people with code: A gentle introduction to C# and Mono Part 2 &#8211; Data Types</a></li>
<li><a href='http://www.sharms.org/blog/2008/09/windows-to-linux-usb-key/' rel='bookmark' title='Permanent Link: Windows to Linux USB key'>Windows to Linux USB key</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>In this post we will cover how to make a basic GUI application using Mono along with Monodevelop.  If you haven&#8217;t already, you will want to read <a href="http://www.sharms.org/blog/2009/07/16/annoying-people-with-code-a-gentle-introduction-to-c-and-mono/">part 1</a> and <a href="http://www.sharms.org/blog/2009/07/17/annoying-people-with-code-a-gentle-introduction-to-c-and-mono-part-2-data-types/">part 2</a> of this series before this article.</p>
<p><strong>Monodevelop</strong><br />
Monodevelop is the tool we are using as our editor.  This is Linux&#8217;s equivalent of Visual Studio.  It can be used to code, debug and design your application, and can link in with revision control systems.  This article was written using version 2.0, if your version is not 2.0 you may see slight differences.</p>
<p><strong>Create your project</strong><br />
After starting Monodevelop, go to <strong>File -> New -> Solution</strong>.  You will be presented with a prompt asking which kind of solution we are starting.  Click on <strong>C# -> Gtk# 2.0 Project</strong> as shown below:</p>
<p><img src="http://www.sharms.org/blog/wp-content/uploads/new-solution.jpg" alt="new-solution" title="new-solution" width="762" height="606" class="aligncenter size-full wp-image-531" /></p>
<p><span id="more-528"></span></p>
<p>Go ahead and click &#8220;Forward&#8221;.  This will drop us at the default Monodevelop screen, and bring up a boilerplate to work from.  For this guide we will mainly be working in the Designer mode.  In the above picture we named our project <b>helloWorldGraphical</b>.  I suggest you name yours the same unless you are already familiar with C#.  Navigate to <b>Solution helloWorldGraphical -> helloWorldGraphical -> User Interface -> MainWindow</b>.  Here you will see the designer window.  If it shows source code, click the Designer tab as shown:</p>
<p><img src="http://www.sharms.org/blog/wp-content/uploads/designer.jpg" alt="designer" title="designer" width="795" height="648" class="aligncenter size-full wp-image-532" /></p>
<p>So now we have a window.  By default, there does not appear to be any buttons to do anything fun with it.  We need to change that by going to <b>View -> Toolbox</b>.  This will allow us to place buttons, boxes, whatever we want.</p>
<p><img src="http://www.sharms.org/blog/wp-content/uploads/toolbox.jpg" alt="toolbox" title="toolbox" width="408" height="441" class="aligncenter size-full wp-image-534" /></p>
<p>Now that we have a bunch of different buttons, what we need is a VBox.  This is a vertical box that will help us position our elements.  Gtk graphical interfaces use containers to figure out what goes where.  For now lets just drag a VBox and leave it with the defaults (just click and drag it on to your window):</p>
<p><img src="http://www.sharms.org/blog/wp-content/uploads/vbox.jpg" alt="vbox" title="vbox" width="650" height="318" class="aligncenter size-full wp-image-535" /></p>
<p>Now that we have a container, we can drag a Label.  A label just allows us to display some arbitrary text, nothing too special.  Go ahead and drag it inside the VBox we just dragged:</p>
<p><img src="http://www.sharms.org/blog/wp-content/uploads/label.jpg" alt="label" title="label" width="600" height="254" class="aligncenter size-full wp-image-537" /></p>
<p>Now that we have a label we can set it&#8217;s text to HelloWorld and get a glympse of how to customize GUI elements.  To do this we need to open the properties window.  To open the properties window go to <b>View -> Properties</b> as shown below:</p>
<p><img src="http://www.sharms.org/blog/wp-content/uploads/properties.jpg" alt="properties" title="properties" width="287" height="590" class="aligncenter size-full wp-image-538" /></p>
<p>Properties is where the magic really happens in the designer.  You can click on your VBox or Label and set a bunch of different values that will change the way your program behaves.  For the purpose of this article, we just want to change the label text:</p>
<p><img src="http://www.sharms.org/blog/wp-content/uploads/label-edit.jpg" alt="label-edit" title="label-edit" width="650" height="233" class="aligncenter size-full wp-image-539" /></p>
<p>Where it says &#8216;label2&#8242; (yours may say different label #), go ahead and change the text to <i>&#8220;Hello World&#8221;</i>.  Your final dialog should look like this:</p>
<p><img src="http://www.sharms.org/blog/wp-content/uploads/final-designer.jpg" alt="final-designer" title="final-designer" width="755" height="401" class="aligncenter size-full wp-image-540" /></p>
<p>Now we are ready to test the program.  Navigate on the top toolbar to the gears icon, which should say &#8216;Debug&#8217;:<br />
<img src="http://www.sharms.org/blog/wp-content/uploads/buildit.jpg" alt="buildit" title="buildit" width="342" height="81" class="aligncenter size-full wp-image-541" /></p>
<p>After clicking the icon, your program will launch and you will see a window as below:</p>
<p><img src="http://www.sharms.org/blog/wp-content/uploads/final.jpg" alt="final" title="final" width="469" height="382" class="aligncenter size-full wp-image-542" /></p>
<p>And now you have your Hello World program.  It doesn&#8217;t do anything, but I am sure in future tutorials we will address that.  For now just play with the designer properties and keep clicking Debug to see your changes.  Good luck!</p>


<p>Related posts:<ol><li><a href='http://www.sharms.org/blog/2009/07/annoying-people-with-code-a-gentle-introduction-to-c-and-mono/' rel='bookmark' title='Permanent Link: Annoying people with code: A gentle introduction to C# and Mono'>Annoying people with code: A gentle introduction to C# and Mono</a></li>
<li><a href='http://www.sharms.org/blog/2009/07/annoying-people-with-code-a-gentle-introduction-to-c-and-mono-part-2-data-types/' rel='bookmark' title='Permanent Link: Annoying people with code: A gentle introduction to C# and Mono Part 2 &#8211; Data Types'>Annoying people with code: A gentle introduction to C# and Mono Part 2 &#8211; Data Types</a></li>
<li><a href='http://www.sharms.org/blog/2008/09/windows-to-linux-usb-key/' rel='bookmark' title='Permanent Link: Windows to Linux USB key'>Windows to Linux USB key</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.sharms.org/blog/2009/07/creating-a-gui-graphical-mono-c-program/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Annoying people with code: A gentle introduction to C# and Mono Part 2 &#8211; Data Types</title>
		<link>http://www.sharms.org/blog/2009/07/annoying-people-with-code-a-gentle-introduction-to-c-and-mono-part-2-data-types/</link>
		<comments>http://www.sharms.org/blog/2009/07/annoying-people-with-code-a-gentle-introduction-to-c-and-mono-part-2-data-types/#comments</comments>
		<pubDate>Fri, 17 Jul 2009 15:07:57 +0000</pubDate>
		<dc:creator>sharms</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[mono]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.sharms.org/blog/?p=496</guid>
		<description><![CDATA[In part one of this series we covered making a basic &#8220;Hello World&#8221; plugin in Mono / C#. Today we are going to dive into different types of data, and how to define them. Show me part 1! Also if you thought part 1 was ugly, I added a new javascript syntax highlighter so I [...]


Related posts:<ol><li><a href='http://www.sharms.org/blog/2009/07/annoying-people-with-code-a-gentle-introduction-to-c-and-mono/' rel='bookmark' title='Permanent Link: Annoying people with code: A gentle introduction to C# and Mono'>Annoying people with code: A gentle introduction to C# and Mono</a></li>
<li><a href='http://www.sharms.org/blog/2009/07/creating-a-gui-graphical-mono-c-program/' rel='bookmark' title='Permanent Link: Annoying people with code: A gentle introduction to C# and Mono Part 3: Creating a GUI (Graphical) Mono / C# Program'>Annoying people with code: A gentle introduction to C# and Mono Part 3: Creating a GUI (Graphical) Mono / C# Program</a></li>
<li><a href='http://www.sharms.org/blog/2009/05/creating-graphs-in-python/' rel='bookmark' title='Permanent Link: Creating graphs in python'>Creating graphs in python</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>In part one of this series we covered making a basic &#8220;Hello World&#8221; plugin in Mono / C#.  Today we are going to dive into different types of data, and how to define them.   <a href="http://www.sharms.org/blog/2009/07/16/annoying-people-with-code-a-gentle-introduction-to-c-and-mono/">Show me part 1!</a>  Also if you thought part 1 was ugly, I added a new javascript syntax highlighter so I recommend you read it on my blog instead of planet.ubuntu.com.</p>
<p><strong>Variables</strong><br />
A variable is something that stores a value.  In different programming languages, these are handled differently.  C# is called a static / strongly typed language as you have to tell it what variables are.  To explain, I will use python in comparison:</p>
<p><strong>Python Example</strong></p>
<pre class="brush: python">
x = &quot;This is a string&quot;
y = 5
</pre>
<p>As you can see, we didn&#8217;t have to tell Python anything about what type of variables they are.  In C# / Mono, we would do this like this:</p>
<p><strong>C# Example</strong></p>
<pre class="brush: csharp">
string x = &quot;This is a string&quot;;
int y = 5;
</pre>
<p>I will tell you, after my years of development, that I program a ton of stuff in PHP / Python today.  One of the worst and best parts of these languages is that they are dynamically typed.  The fact that C# requires variables to be declared with a type before using makes life easier for testing and reading.  There is a stack overflow post on what static typing gives you: <a href="http://stackoverflow.com/questions/859186/why-is-c-statically-typed">Read the stack overflow post.</a></p>
<p><strong>Variable Naming</strong><br />
Before we continue, you will notice in the top example I used the variable names x and y <em>(to illustrate that the variable names really mean nothing to the compiler / interpreter.  If I named them myString you might have been confused)</em>.  If you do this in real life, I will find you and give you a thorough verbal lashing.  I generally use camel case to name variables.  Just do not abbreviate them as it really serves no purpose, and makes a lot of pain for people besides yourself maintaining code.</p>
<p>You can read about <a href="http://en.wikipedia.org/wiki/CamelCase">camel case at wikipedia.</a></p>
<p><strong>The Source</strong><br />
For this program, I copied our HelloWorld.cs, and just modified it.  I also have a modified makefile.</p>
<p><strong>dataTypes.cs</strong></p>
<pre class="brush: csharp">
using System;

// We create a class to contain it
class dataTypes
{
    static void Main(string[] args)
    {
        // The type &#039;bool&#039; is always true or false
        bool isMonoTheOnlyPatentRisk = false;

        // To check if it is true or false in program code,
        // we can use an &#039;if statement&#039;
        if(isMonoTheOnlyPatentRisk)
        {
            Console.WriteLine(&quot;isMonoTheOnlyPatentRisk was set to true&quot;);
        } else
        {
            Console.WriteLine(&quot;isMonoTheOnlyPatentRisk was set to false&quot;);
        }

        // Note how I named the variables -
        // lowercaseFirstThenCapitalizeEachWorld
        // this is called camel case -- I first read about it
        // in a Charles Petzold book, but I am sure it
        // probably didn&#039;t originate there.  Either way its
        // how I code, I recommend you name variables
        // as descriptive as possible.

        // Note to only kids:  You will have the initial
        // reaction of saying: Why should I name stuff long?
        // That takes time and is stupid!
        // I used to be you 10 years ago, the problem is if
        // you need to use your code in several years of not
        // using it.  Your time will be completely wasted
        // figuring out what the heck is going on, despite
        // seeming so intuitive / easy to understand when you
        // did it

        // Integers store numbers
        int ourNumber = 5;

        // In most langauges we can evaluate these in
        // &#039;if statements&#039; like bools above, but if we try in
        // C# this will fail.  In C# a bool can only be 0 for
        // false, 1 for true, or we can use the
        // Convert.ToBoolean function like this:
        if(Convert.ToBoolean(ourNumber))
        {
            Console.WriteLine(&quot;ourNumber was not 0!&quot;);
        } else
        {
            Console.WriteLine(&quot;ourNumber was 0&quot;);
        }

        // Lets see if we can compare this number
        if(ourNumber &gt; 4)
        {
            Console.WriteLine(&quot;ourNumber was greater than 4&quot;);
        } else
        {
            Console.WriteLine(&quot;ourNumber was less than or equal to 4&quot;);
        }

        // Make a string, and output it
        string helloWorldVariable = &quot;Hello World!&quot;;
        Console.WriteLine(helloWorldVariable);
    }
}
</pre>
<p><strong>Makefile</strong></p>
<pre class="brush: sh">
COMPILER=gmcs

all: helloWorld.exe dataTypes.exe

helloWorld.exe: helloWorld.cs
	$(COMPILER) helloWorld.cs

dataTypes.exe: dataTypes.cs
	$(COMPILER) dataTypes.cs
clean:
	rm -f helloWorld.exe dataTypes.exe

.PHONY: all clean
</pre>
<p><strong>Output from our terminal</strong></p>
<pre class="brush: sh">
[sharms@sparrow mono]$ make
gmcs helloWorld.cs
gmcs dataTypes.cs
[sharms@sparrow mono]$ mono dataTypes.exe
isMonoTheOnlyPatentRisk was set to false
ourNumber was not 0!
ourNumber was greater than 4
Hello World!
</pre>
<p><strong>Bonus Tip</strong><br />
Did you notice in the first part the way I named the bool?  If you are programming, generally, your bool&#8217;s should start with &#8216;is&#8217;.  This becomes very important once you start making complex &#8216;if statements&#8217;.  Trust me on this one, it&#8217;s a habit you want.</p>


<p>Related posts:<ol><li><a href='http://www.sharms.org/blog/2009/07/annoying-people-with-code-a-gentle-introduction-to-c-and-mono/' rel='bookmark' title='Permanent Link: Annoying people with code: A gentle introduction to C# and Mono'>Annoying people with code: A gentle introduction to C# and Mono</a></li>
<li><a href='http://www.sharms.org/blog/2009/07/creating-a-gui-graphical-mono-c-program/' rel='bookmark' title='Permanent Link: Annoying people with code: A gentle introduction to C# and Mono Part 3: Creating a GUI (Graphical) Mono / C# Program'>Annoying people with code: A gentle introduction to C# and Mono Part 3: Creating a GUI (Graphical) Mono / C# Program</a></li>
<li><a href='http://www.sharms.org/blog/2009/05/creating-graphs-in-python/' rel='bookmark' title='Permanent Link: Creating graphs in python'>Creating graphs in python</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.sharms.org/blog/2009/07/annoying-people-with-code-a-gentle-introduction-to-c-and-mono-part-2-data-types/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Annoying people with code: A gentle introduction to C# and Mono</title>
		<link>http://www.sharms.org/blog/2009/07/annoying-people-with-code-a-gentle-introduction-to-c-and-mono/</link>
		<comments>http://www.sharms.org/blog/2009/07/annoying-people-with-code-a-gentle-introduction-to-c-and-mono/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 20:32:01 +0000</pubDate>
		<dc:creator>sharms</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[mono]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.sharms.org/blog/?p=493</guid>
		<description><![CDATA[This is meant to be an introduction to C# and Mono. First, we need to download the mono runtime and compiler: sudo apt-get install monodevelop mono-devel For the purpose of this post, we are just going to create a simple program which prints out the text &#8220;Hello World&#8221;. Go ahead and make a directory for [...]


Related posts:<ol><li><a href='http://www.sharms.org/blog/2009/07/annoying-people-with-code-a-gentle-introduction-to-c-and-mono-part-2-data-types/' rel='bookmark' title='Permanent Link: Annoying people with code: A gentle introduction to C# and Mono Part 2 &#8211; Data Types'>Annoying people with code: A gentle introduction to C# and Mono Part 2 &#8211; Data Types</a></li>
<li><a href='http://www.sharms.org/blog/2009/07/creating-a-gui-graphical-mono-c-program/' rel='bookmark' title='Permanent Link: Annoying people with code: A gentle introduction to C# and Mono Part 3: Creating a GUI (Graphical) Mono / C# Program'>Annoying people with code: A gentle introduction to C# and Mono Part 3: Creating a GUI (Graphical) Mono / C# Program</a></li>
<li><a href='http://www.sharms.org/blog/2009/02/finding-the-difference-between-two-files/' rel='bookmark' title='Permanent Link: Finding the difference between two files'>Finding the difference between two files</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>This is meant to be an introduction to C# and Mono.   First, we need to download the mono runtime and compiler:</p>
<pre class="brush: sh">
sudo apt-get install monodevelop mono-devel
</pre>
<p>For the purpose of this post, we are just going to create a simple program which prints out the text &#8220;Hello World&#8221;.  Go ahead and make a directory for our project so we don&#8217;t make our home directory entirely too messy.  I just make a directory called &#8216;mono&#8217; under /home/sharms/mono for the duration of this post.</p>
<p>Go ahead and create a file called &#8216;helloWorld.cs&#8217;, and paste the following:</p>
<pre class="brush: csharp">
// Declare which namespace we want to use.
// This allows us to use Console.WriteLine
// instead of System.Console.WriteLine
// Basically like a python &#039;import&#039; statement, or a
// php &#039;include&#039; statement
using System;

// We create a class to contain it
class HelloWorld
{
    // Must have a main function as this is what is
    // first called when executing this
    static void Main()
    {
         // C# requires ; after statements
         // Actually output &quot;Hello World&quot;
        Console.WriteLine(&quot;Hello World&quot;);
    }
}
</pre>
<p>To compile it, run:</p>
<pre class="brush: sh">
gmcs helloWorld.cs
</pre>
<p>This will generate a file called &#8216;helloWorld.exe&#8217;.  To run it, type:</p>
<pre class="brush: sh">
mono helloWorld.exe
Hello World
</pre>
<p>And there you have it.  I also stumbled on a Makefile tutorial today, so we can make a simple make file (I won&#8217;t describe all of this, just look at how it&#8217;s used).  The tutorial is at: <a href="http://www.wlug.org.nz/MakefileHowto">http://www.wlug.org.nz/MakefileHowto</a></p>
<pre class="brush: sh">
[sharms@sparrow mono]$ cat Makefile
COMPILER=gmcs

all: helloWorld.exe

helloWorld.exe: helloWorld.cs
	$(COMPILER) helloWorld.cs

clean:
	rm -f helloWorld.exe

.PHONY: all clean
[sharms@sparrow mono]$ make
gmcs helloWorld.cs
[sharms@sparrow mono]$ make clean
rm -f helloWorld.exe
</pre>


<p>Related posts:<ol><li><a href='http://www.sharms.org/blog/2009/07/annoying-people-with-code-a-gentle-introduction-to-c-and-mono-part-2-data-types/' rel='bookmark' title='Permanent Link: Annoying people with code: A gentle introduction to C# and Mono Part 2 &#8211; Data Types'>Annoying people with code: A gentle introduction to C# and Mono Part 2 &#8211; Data Types</a></li>
<li><a href='http://www.sharms.org/blog/2009/07/creating-a-gui-graphical-mono-c-program/' rel='bookmark' title='Permanent Link: Annoying people with code: A gentle introduction to C# and Mono Part 3: Creating a GUI (Graphical) Mono / C# Program'>Annoying people with code: A gentle introduction to C# and Mono Part 3: Creating a GUI (Graphical) Mono / C# Program</a></li>
<li><a href='http://www.sharms.org/blog/2009/02/finding-the-difference-between-two-files/' rel='bookmark' title='Permanent Link: Finding the difference between two files'>Finding the difference between two files</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.sharms.org/blog/2009/07/annoying-people-with-code-a-gentle-introduction-to-c-and-mono/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>

