Simple HelloWorld Program in GTK# 2.0 Mono Develop?

MonoDevelop is cross platform IDE to develop desktop application for Linux/windows/Mac OSX.

GTK:-

1. GTK (GIMP ToolKit) is a library to create graphical user interface. GTK is an object oriented programmers interface. Its completely written in C.

2. GTK# is wrapper over the GTK+ for the C# programming language. Application built using GTK# can run on multi platform such as Linux, windows and MAC OSX.

3. GTK# is part of the mono IDE.

Download MonoDevelop IDE from http://monodevelop.com/Download for mac and windows.

Simple Hello World program in GTK# MonoDevelop

Step 1. Run /Applications/Xamarin Studio and create new solution.

File->New->Solution

Step 2. Select language C# and then GTK# 2.0 project from new solution Diaolg and assign name HelloWorld.
You would have default references and two files such as MainWindow.cs and Program.cs.
In Program.cs , your application instance is created and initialize it with main window creation.

Step 3. Now,  open the MainWindow.cs in design mode and just need to place one button over the main window.
Before placing the button over window first need to place one container control which contain the button.

3.1 Open the Toolbox:View->Pads->Toolbox and select Fixed container and drag over the window.

3.2 Drag and drop the button over the Fixed container and rename it from properties (Button Properties).
if property window not visible then select button and then View->Pads->Properties and you will see the property window in right side.

Step 4. Create button action: First need to create button clicked event in MainWindow.cs.

Just select button and then move to properties window and then select Signal tab and then expand button signals and double clicked on Clicked.

You will see a button event handler in MainWindow.cs like as:

protectedvoid OnButton4Clicked (object sender, EventArgs e)
{
throw new NotImplementedException ();
}

Step 5. Display Message Box on button clicked event. Just add following code in button clicked event handler.

protectedvoid OnButton4Clicked (object sender, EventArgs e)
{
MessageDialog md = new MessageDialog (this, DialogFlags.DestroyWithParent,
MessageType.Info,
ButtonsType.Ok, “HelloWorld!!!”);
md.Run ();
md.Destroy();
}

Step 6. Run and launch the application and you will see a window with button and when you click on a button you will see a message box.
In next blog will show you how to create .app bundle from release exe from GTK# mono develop which you can run on MAC OSX.

Written By: Yogesh Arora, Software Engineer, Mindfire Solutions

Reference from:

http://monodevelop.com

http://zetcode.com/gui/gtksharp/

Advertisements

About yogesha2014

Currently, i am working in MindfireSolution as cocoa application developer. I have 2+ year of experience in mac desktop application development. Also have knowledge about VC++ win32, MFC and MonoDevelop GTK#2.0.

Posted on November 7, 2014, in Mono and tagged , , , , . Bookmark the permalink. Comments Off on Simple HelloWorld Program in GTK# 2.0 Mono Develop?.

Comments are closed.

%d bloggers like this: