64 lines
2.1 KiB
C#
64 lines
2.1 KiB
C#
using laba3.Core;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
|
||
namespace ProgLab1.GUI
|
||
{
|
||
public partial class MenuForm : Form
|
||
{
|
||
public MenuForm()
|
||
{
|
||
InitializeComponent();
|
||
}
|
||
|
||
/// <summary>
|
||
/// Adds menu to GUI
|
||
/// </summary>
|
||
/// <param name="consoleMenu">TUI menu</param>
|
||
public void AddMenu(Menu consoleMenu)
|
||
{
|
||
|
||
FlowLayoutPanel buttonPanel = new FlowLayoutPanel
|
||
{
|
||
Dock = DockStyle.Fill, // Растягиваем на всю форму
|
||
FlowDirection = FlowDirection.TopDown, // Кнопки располагаются сверху вниз
|
||
WrapContents = false // Запрет переноса
|
||
};
|
||
|
||
Label menuLabel = new Label
|
||
{
|
||
Text = consoleMenu.GetTitle(), // Текст заголовка
|
||
Font = new System.Drawing.Font("Arial", 16, System.Drawing.FontStyle.Bold), // Стиль шрифта
|
||
TextAlign = System.Drawing.ContentAlignment.MiddleCenter, // Выравнивание текста по центру
|
||
Dock = DockStyle.Top, // Заголовок сверху
|
||
Height = 40 // Высота заголовка
|
||
};
|
||
|
||
buttonPanel.Controls.Add(menuLabel);
|
||
|
||
foreach (MenuOption option in consoleMenu.GetOptions())
|
||
{
|
||
Button button = new Button
|
||
{
|
||
Text = option.Name,
|
||
Width = buttonPanel.Width-10,
|
||
Height = 40,
|
||
Margin = new Padding(5),
|
||
};
|
||
|
||
// Связываем обработчик с OnSelect из консольного меню
|
||
button.Click += (sender, e) => option.Action();
|
||
|
||
buttonPanel.Controls.Add(button);
|
||
}
|
||
}
|
||
}
|
||
}
|