В програмі Visual Studio Code створюємо новий проектdotnet new console
Додаємо до проекту пакет GirCore.Gtkdotnet add package GirCore.Gtk-4.0
Запуск програмиdotnet run
Program.cs
using Gtk; class Program { static void Main() { var app = Application.New("ua.org.accounting.test", Gio.ApplicationFlags.FlagsNone); app.OnActivate += (sender, args) => { FirstWindow firstWindow = new(app); firstWindow.Show(); }; app.RunWithSynchronizationContext(null); } }
using Gtk; using static Gtk.Orientation; class FirstWindow : Window { public FirstWindow(Application app) : base() { Application = app; Title = "MessageDialog"; SetDefaultSize(500, 300); Box vBox = Box.New(Vertical, 0); vBox.MarginTop = vBox.MarginBottom = vBox.MarginStart = vBox.MarginEnd = 10; Child = vBox; Button button = Button.NewWithLabel("Діалог"); button.OnClicked += (_, _) => { MessageDialog messageDialog = new() { TransientFor = this, Application = app, Modal = true, Valign = Align.Center, Halign = Align.Center }; messageDialog.Text = "Заголовок повідомлення"; messageDialog.SecondaryText = "Text Text Text Text Text\nText Text Text Text Text\nText Text Text Text Text"; if (messageDialog.MessageArea != null && messageDialog.MessageArea is Box box) box.Append(Image.NewFromIconName("application-exit")); messageDialog.AddButton("Ok", 1); messageDialog.AddButton("Next", 2); messageDialog.AddButton("Close", 3); messageDialog.OnResponse += (_, arrg) => { Console.WriteLine(arrg.ResponseId); messageDialog.Hide(); messageDialog.Destroy(); }; messageDialog.Show(); }; Box hBox = Box.New(Horizontal, 5); hBox.Append(button); vBox.Append(hBox); } }
Visual Studio Code
Віджети Gtk 4
NuGet пакет GirCore.Gtk-4.0
© accounting.org.ua - 2025