Search code examples
monodevelopgtk#

How can I access Gtk# widgets in code in MonoDevelop?


First, I am new to Monodevelop and Gtk# (but have experience with Visual Studio, C# and Winforms).

In Monodevelop I designed a form by dragging widgets onto it. I entered a value for the Name and (the same or a different value) for the MemberName. However I can't access the widgets in code.

In Visual Studio there is a form.Designer.cs which contains the code that creates the controls. What is the equivalent in MonoDevelop? I would like to examine the code so I can learn from it, and to find out how I can access a widget in code.

I am using MonoDevelop 5.5, Mono 3.10.0 on Linux Mint 17.1 64-bit.

(This question has been asked before, but that answer doesn't help me).


Solution

  • The GTK# generated code will be in a .cs file inside a gtk-gui directory inside your project. The .cs file will have a similar name to your widget class name but will have the full namespace of the class as part of its name.

    MyWidget.cs
    gtk-gui/MyGtkApp.MyWidget.cs
    

    Also you will need to compile your project before the code is generated. The new member names should be available from within the widget's class.