dotnet new console
dotnet add package GtkSharp
dotnet run
using Gtk; class Program { public static void Main() { Application.Init(); new FirstWindow(); Application.Run(); } public static void Quit() { Application.Quit(); } }
using Gtk; class FirstWindow : Window { public FirstWindow() : base("Test") { SetDefaultSize(600, 350); SetPosition(WindowPosition.Center); DeleteEvent += delegate { Program.Quit(); }; VBox vBox = new VBox(); Add(vBox); HBox hBox = new HBox(); vBox.PackStart(hBox, false, false, 5); //Simple { Button button = new Button("Кнопка"); button.Clicked += (object? sender, EventArgs args) => { Console.WriteLine("Click"); }; hBox.PackStart(button, false, false, 5); } //Image { Button button = new Button { AlwaysShowImage = true, Image = Image.NewFromIconName(Stock.Cancel, IconSize.Button), }; button.Clicked += (object? sender, EventArgs args) => { Console.WriteLine("Click"); }; hBox.PackStart(button, false, false, 5); } //Image + Text { Button button = new Button { Label = "Додати", ImagePosition = PositionType.Left, AlwaysShowImage = true, Image = Image.NewFromIconName(Stock.Add, IconSize.Button), }; button.Image.MarginEnd = 5; button.Clicked += (object? sender, EventArgs args) => { Console.WriteLine("Click"); }; hBox.PackStart(button, false, false, 5); } //Stock { Button button = new Button(Stock.Edit); button.Clicked += (object? sender, EventArgs args) => { Console.WriteLine("Click"); }; hBox.PackStart(button, false, false, 5); } ShowAll(); } }
© accounting.org.ua - 2024