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 { Toolbar ToolbarTop = new Toolbar(); public FirstWindow() : base("Test") { SetDefaultSize(600, 600); SetPosition(WindowPosition.Center); DeleteEvent += delegate { Program.Quit(); }; VBox vBox = new VBox(); Add(vBox); vBox.PackStart(ToolbarTop, false, false, 0); CreateToolbar(); ShowAll(); } void CreateToolbar() { ToolButton addButton = new ToolButton(new Image(Stock.Add, IconSize.Menu), "Додати") { TooltipText = "Додати" }; addButton.Clicked += OnAddClick; ToolbarTop.Add(addButton); ToolItem toolItemSeparator = new ToolItem { new Separator(Orientation.Horizontal) }; ToolbarTop.Add(toolItemSeparator); MenuToolButton button = new MenuToolButton(new Image(Stock.Find, IconSize.Menu), "Кроки") { IsImportant = true }; button.Clicked += OnMenuButtonClick; button.Menu = ToolbarSubMenu(); ToolbarTop.Add(button); } Menu ToolbarSubMenu() { Menu Menu = new Menu(); { MenuItem item = new MenuItem("Крок 1"); item.Activated += (object? sender, EventArgs args) => { }; Menu.Append(item); } { MenuItem item = new MenuItem("Крок 2"); item.Activated += (object? sender, EventArgs args) => { }; Menu.Append(item); } Menu.ShowAll(); return Menu; } void OnAddClick(object? sender, EventArgs args) { } void OnMenuButtonClick(object? sender, EventArgs args) { if (sender != null) ((Menu)((MenuToolButton)sender).Menu).Popup(); } }
© accounting.org.ua - 2024