GTK# in Visual Studio 2008 on Vista x64

Yes, I am crazy. Why would any programmer want this combination? I think it is a combination of wanting to work with the best tools, in this case Visual Studio 2008 and CodeRush and wanting to target Win32, OSX, and Linux all at once. The very nice part is that thanks to the hard work of other people, you don’t even have to run in Mono on Win32.

  1. Install the GTK# SDK
    You can get it from here: http://medsphere.org/projects/gtksharp/releases/2.10.4/gtksharp-sdk-2.10.4.msi
    The project page is here:
    http://medsphere.org/projects/gtksharp/
    Thanks to the good folks at medsphere for maintaining this windows installer. Presumably they use this in their applications.
  2. Create a new Windows Forms Project in Visual Studio.
    newGTK#_2008-10-30_19-54-28
    Its fine to keep 3.5 framework selected. Mono supports the core parts of 3.5.
  3. Remove the references to System.Windows.Forms.dll
  4. Add reference to atk-sharp, glib-sharp and gtk-sharp in the following paths:
    C:\Program Files (x86)\Medsphere\Gtk# Runtime\lib\gtk-sharp-2.0\atk\atk-sharp.dll
    C:\Program Files (x86)\Medsphere\Gtk# Runtime\lib\gtk-sharp-2.0\glib\glib-sharp.dll
    C:\Program Files (x86)\Medsphere\Gtk# Runtime\lib\gtk-sharp-2.0\gtk\gtk-sharp.dll
  5. Change your Platform target to x86 from AnyCPU in the project properties.
    projectTarget_2008-10-30_20-00-11
  6. Write some test code
  7. [STAThread]
    static void Main()
    {
        Application.Init();
        Window myWin = new Window("My first GTK# Application! ");
        myWin.Resize(200, 200);
        myWin.Destroyed += new EventHandler(myWin_Destroyed);
        Label myLabel = new Label();
        myLabel.Text = "Hello World!!!!";
        myWin.Add(myLabel);
        myWin.ShowAll();
        Application.Run();
    }
    static void myWin_Destroyed(object sender, EventArgs e)
    {
        Application.Quit();
    }
  8. Run the application

Enjoy your 3rd option for a pure .NET programming GUI Toolkit on Win32. Winforms and WPF are great, but GTK# does fill a certain niche.

14 thoughts on “GTK# in Visual Studio 2008 on Vista x64”

  1. Don’t throw a shoe at me…but.. what do you gain by doing this? When ever I read posts like this – it makes me wonder – “Am I missing a better way of doing stuff – is this something cool that could my life easier?”

  2. This is acctually great ,,, i have been searching for this kind of solution for a long time. The only thing that i can not find is something like build in linq using gtk ,, this would be the ultimate solution. thanks for this post dude

  3. hi,

    you have a comment on Scotts article onlMerge.
    http://www.hanselman.com/blog/MixingLanguagesInASingleAssemblyInVisualStudioSeamlesslyWithILMergeAndMSBuild.aspx

    i have tried to build two projects in visual studio as you defined but cannot get successful.
    .netmodule produced for the second project is referenced as an external file but not linked, when its deleted the .exe file does not work.
    am i missing something or its not possible to achieve within visual studio but by writing a make file?
    thanks in advance

    sorry for the inconvenience to ask here.

  4. @David Pierce

    I think you are correct, you cannot do it with Visual Studio. You may be able to do it with some custom msbuild rules, but my guess is that the Visual Studio experience will be very different than using project references. This is a major gripe of mine with the way Visual Studio utilizes msbuild.

    Try a makefile or custom msbuild targets.

  5. @dave pease

    I won’t throw a shoe at you. I am an old linux guy, but I do like Visual Studio, so I want to write apps which target both Linux AND Windows and GTK# seems to be the best way to do that. If you don’t care about linux, then you can safely ignore this. You aren’t missing anything.

  6. @Konstantin

    What specifically do you mean “build in linq using gtk” You can use GTK# and all of the features of Linq in both Windows .NET and in Linux.

  7. Great post Jay!
    The bad point is that you loose the Monodevelop’s Stetic designer which is the best designer to me. But is good to know that the posibility is there.
    I am still working on DesktopRails to offer Gtk#/Windows.Forms/WPF portability.
    Cheers mate

  8. Hi Jay,
    what I i ment in my post was the ability to use full data binding using linq to mysql not MSsql altogether with GTK# without mono . I am not quite sure if you can do that yet!

  9. I’m not familiar with linq to mysql, but it should work fine with nhibernate based objects or dblinq objects.

    honestly, I’m not familiar enough with GTK# full data binding to comment on the details. I’ll look into it.

  10. @lxx

    No, the visual form designer is for windows forms.

    It turns out that even in winforms, the form designer becomes far less useful once you want to do certain things. I stopped using the forms designer because it is too slow, and I can get more done without it.

    nice blog BTW, I wish I read Russian.

  11. I ended up doing this and it works quite well. I also reference glade-sharp and use the glade-3 UI editor.

    Thanks!

  12. thank you for sharing

    [STAThread]
    static void Main()
    {
    Application.Init();
    Window myWin = new Window(“My first GTK# Application! “);
    myWin.Resize(200, 200);
    myWin.Destroyed += new EventHandler(myWin_Destroyed);
    Label myLabel = new Label();
    myLabel.Text = “Hello World!!!!”;
    myWin.Add(myLabel);
    myWin.ShowAll();
    Application.Run();
    }
    static void myWin_Destroyed(object sender, EventArgs e)
    {
    Application.Quit();
    }

Comments are closed.