Before beginning, create a new Gtk# project and add references to the following assemblies:
TwoLayeredGUI.dll
TwoLayeredGUI.GtkSharp.dll
Alternatively, you can also install the NuGet package TwoLayeredGUI.GtkSharp
; it will automatically add the two mentioned assemblies.
As we are going to try various functions offered by the Two-Layered GUI Toolkit, it is a good idea to structure the main window of the application in a way that it can contain a large number of buttons, menu items, or whichever controls you want to use. For your convenience, here is a code skeleton for such a Gtk# program:
using System; using Gtk; namespace Tutorial { class Program { private static VBox layoutMain; private static void AddButton(string title, System.Action action) { Button btn = Button.NewWithLabel(title); layoutMain.PackStart(btn, false, false, 0); btn.Clicked += delegate { action(); }; } [STAThread] public static void Main(string[] args) { Application.Init(); using (Window win = new Window("Tutorial for the Two-Layered GUI Toolkit")) { try { win.Hidden += delegate { Application.Quit(); }; win.WindowPosition = WindowPosition.Center; win.SetSizeRequest(300, 550); layoutMain = new VBox(false, 0); win.Add(layoutMain); // add buttons here by calling AddButton win.ShowAll(); Application.Run(); } finally { win.Destroy(); } } } } }
With this code, simply call the AddButton
method, specify what you are trying and add the method that contains your code, and a button will be inserted on your window.
Lastly, to add a first bit of the Two-Layered GUI Toolkit to our code, add the following two using
directives:
using TwoLayeredGUI; using TwoLayeredGUI.Gtk;
The first namespace is the general root namespace for the Two-Layered GUI Toolkit and contains many of the types that we will use throughout this tutorial. The second namespace is the root namespace for the Gtk# binding; if you use a binding for another GUI toolkit, make sure to replace this with the appropriate namespace.
Now that we're set, we can start displaying some dialog boxes.
Wiki: Help-Tutorial-Direct-MessageBoxes
Wiki: Help-Tutorial-Direct