В програмі 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 static void MarginAll(Box box) => box.MarginTop = box.MarginBottom = box.MarginStart = box.MarginEnd = 10; public FirstWindow(Application app) : base() { Application = app; Title = "Notebook"; SetDefaultSize(500, 300); Box vBox = Box.New(Vertical, 0); MarginAll(vBox); Child = vBox; Notebook notebook = Notebook.New(); notebook.Vexpand = true; // Page 1 { Box vBoxPage = Box.New(Vertical, 10); MarginAll(vBoxPage); Box hBoxPage = Box.New(Horizontal, 10); hBoxPage.Append(Calendar.New()); vBoxPage.Append(hBoxPage); notebook.AppendPage(vBoxPage, Label.New("Page 1")); notebook.SetTabReorderable(vBoxPage, true); } // Page 2 { Box vBoxPage = Box.New(Vertical, 10); MarginAll(vBoxPage); for (int i = 1; i <= 15; i++) { Box hBoxPage = Box.New(Horizontal, 10); hBoxPage.Append(Label.New($"Label {i}")); vBoxPage.Append(hBoxPage); } ScrolledWindow scroll = ScrolledWindow.New(); scroll.SetPolicy(PolicyType.Automatic, PolicyType.Automatic); scroll.Child = vBoxPage; notebook.AppendPage(scroll, Label.New("Page 2")); notebook.SetTabReorderable(scroll, true); } // Page 3 { Box vBoxPage = Box.New(Vertical, 10); MarginAll(vBoxPage); for (int i = 1; i <= 15; i++) { Box hBoxPage = Box.New(Horizontal, 10); hBoxPage.Append(Button.NewWithLabel($"Button {i}")); vBoxPage.Append(hBoxPage); } ScrolledWindow scroll = ScrolledWindow.New(); scroll.SetPolicy(PolicyType.Automatic, PolicyType.Automatic); scroll.Child = vBoxPage; notebook.AppendPage(scroll, Label.New("Page 3")); notebook.SetTabReorderable(scroll, true); } vBox.Append(notebook); } }
Visual Studio Code
Віджети Gtk 4
NuGet пакет GirCore.Gtk-4.0
© accounting.org.ua - 2025