button.Clicked += delegate { // code to be executed when button is clicked };
using Gtk; public class MainWindow : Gtk.Window { Button button; Label label; public MainWindow() : base("Hello World") { SetDefaultSize(250, 150); SetPosition(WindowPosition.Center); DeleteEvent += delegate { Application.Quit(); }; button = new Button("Click me"); button.Clicked += delegate { label.Text = "Button clicked"; }; label = new Label("Hello World"); var vbox = new VBox(false, 5); vbox.PackStart(label, true, true, 0); vbox.PackStart(button, false, false, 0); Add(vbox); ShowAll(); } } public class App { public static void Main() { Application.Init(); new MainWindow(); Application.Run(); } }The above code creates a simple GTK window with a label and a button. When the button is clicked, the label text is changed to "Button clicked".