using System; using System.Drawing; using System.Windows.Forms; namespace UI { /// /// Abre qualquer UserControl dentro de um Form genérico, /// sem precisar criar uma classe Form para cada tela. /// public static class FormHelper { // ══════════════════════════════════════════════════════════════════════ // ABRE UM USERCONTROL GENÉRICO // Uso: FormHelper.Show("Agenda"); // ══════════════════════════════════════════════════════════════════════ public static void Show( string titulo, int width = 1150, int height = 780, Action? configure = null) // opcional: configurar o painel antes de abrir where TPanel : UserControl, new() { using var form = BuildForm(titulo, width, height); var panel = new TPanel(); configure?.Invoke(panel); form.Controls.Add(panel); form.ShowDialog(); } // ══════════════════════════════════════════════════════════════════════ // ABRE UM USERCONTROL JÁ INSTANCIADO (útil quando precisa passar dados) // Uso: FormHelper.Show(new AgendaCadastroPanel(), "Agenda"); // ══════════════════════════════════════════════════════════════════════ public static void Show( UserControl panel, string titulo, int width = 1150, int height = 780) { using var form = BuildForm(titulo, width, height); form.Controls.Add(panel); form.ShowDialog(); } // ══════════════════════════════════════════════════════════════════════ // ABRE UM FORM QUALQUER (mantém compatibilidade com o showForms) // Uso: FormHelper.ShowForm(); // ══════════════════════════════════════════════════════════════════════ public static void ShowForm() where TForm : Form, new() { using var form = new TForm(); form.StartPosition = FormStartPosition.CenterScreen; form.ShowDialog(); } // ── BUILDER INTERNO ─────────────────────────────────────────────────── private static Form BuildForm(string titulo, int width, int height) { return new Form { Text = titulo, Size = new Size(width, height), StartPosition = FormStartPosition.CenterScreen, BackColor = Color.White, MinimumSize = new Size(800, 500), Icon = System.Drawing.Icon.ExtractAssociatedIcon( System.Reflection.Assembly.GetEntryAssembly()!.Location) }; } } }