Popup Container
An editor with a drop-down that can hold any control you like: a read-only text box showing a value, and a button beside it that opens a resizable pop-up containing your own content – a calendar, a tree of categories, a colour grid, a filter panel.
Assembly
| Assembly | Binarymission.WinForms.Controls.PopupEditor.dll |
| Root namespace | Binarymission.WinForms.Controls.ContainerPopups |
| Target frameworks | .NET Framework 4.8, .NET 6 / 8 / 10 |
| Depends on | BinaryExtendedText, BinaryMenu, BinaryScrollBars, BinaryScrollerPanel |
Overview
Use it where a combo box is the right shape but a list is the wrong content. You supply the
content as any Control in PopupContentHost; when the user has made a choice
in it, set DisplayText to show the result and call ClosePopup.
The two halves
The text box takes DisplayTextVisualToTotalSizeRatio per cent of the width (80 by
default) and the button the rest. The text box is styled with the TextDisplayVisual...
properties; the button with the PopupCommandVisual... properties – its colours in the normal,
hover and pressed states, and either a down-arrow image (built in, or your own) or a short text.
The drop-down
A click on the button calls Show, which opens the drop-down under the editor (or at
DisplayLocation) at DropDownSize; a second click closes it, as does a click
anywhere else. With EnableDropDownResizing on, a strip along its foot lets the user drag
it taller or, from the corner, larger, and the size they choose is kept for next time
(ShouldRememberUserSizedDropDownSize). DropDownPopupOpened,
DropDownPopupClosing and DropDownPopupClosed follow it.
Getting started
A "Due date" editor whose drop-down is a MonthCalendar.
using System;
using System.Drawing;
using System.Windows.Forms;
using Binarymission.WinForms.Controls.ContainerPopups;
public class TaskForm : Form
{
private readonly PopupEditor _dueDate = new PopupEditor();
private readonly MonthCalendar _calendar = new MonthCalendar { MaxSelectionCount = 1 };
public TaskForm()
{
_dueDate.Location = new Point(16, 16);
_dueDate.Size = new Size(220, 30);
_dueDate.DisplayText = "Choose a date";
_dueDate.TextDisplayVisualFont = new Font("Segoe UI", 10f);
_dueDate.PopupCommandVisualNormalBackColor = Color.SteelBlue;
_dueDate.PopupCommandVisualBorderColor = Color.SteelBlue;
_dueDate.PopupCommandVisualHoveredBackColor = Color.RoyalBlue;
_dueDate.PopupCommandVisualBorderColorOnHover = Color.RoyalBlue;
_dueDate.TextDisplayVisualBorderColor = Color.SteelBlue;
_dueDate.PopupContentHost = _calendar;
_dueDate.EnableDropDownResizing = false;
_calendar.DateSelected += (sender, e) =>
{
_dueDate.DisplayText = e.Start.ToString("ddd d MMM yyyy");
_dueDate.ClosePopup();
};
Controls.Add(_dueDate);
}
}API reference
Binarymission.WinForms.Controls.ContainerPopups
class PopupContentHost | A scrolling panel ready-styled to be the content of a PopupEditor drop-down: put the controls of your drop-down in it and it scrolls them with themed scroll bars when they do not fit. |
class PopupEditor | An editor with a drop-down that can hold any control you like: a read-only text box showing a value, and a button beside it that opens a resizable pop-up containing your own content - a calendar, a tree of categories, a colour grid, a filter panel. |