| 1 | using System.ComponentModel; |
| 2 | |
| 3 | namespace Cage.Windows; |
| 4 | |
| 5 | internal sealed class TrayMenu : ContextMenuStrip |
| 6 | { |
| 7 | public TrayMenu() |
| 8 | { |
| 9 | ShowImageMargin = false; |
| 10 | ShowCheckMargin = false; |
| 11 | DropShadowEnabled = true; |
| 12 | Font = new Font(SystemFonts.MenuFont!.FontFamily, 9.5f, FontStyle.Regular, GraphicsUnit.Point); |
| 13 | } |
| 14 | |
| 15 | protected override void OnOpening(CancelEventArgs e) |
| 16 | { |
| 17 | base.OnOpening(e); |
| 18 | Padding = new Padding(LogicalToDeviceUnits(6)); |
| 19 | int width = LogicalToDeviceUnits(208); |
| 20 | foreach (ToolStripItem item in Items) |
| 21 | { |
| 22 | if (item is ToolStripSeparator) continue; |
| 23 | item.Padding = new Padding(LogicalToDeviceUnits(12), LogicalToDeviceUnits(7), |
| 24 | LogicalToDeviceUnits(12), LogicalToDeviceUnits(7)); |
| 25 | width = Math.Max(width, item.GetPreferredSize(Size.Empty).Width + Padding.Horizontal); |
| 26 | } |
| 27 | foreach (ToolStripItem item in Items) |
| 28 | { |
| 29 | int height = item is ToolStripSeparator ? LogicalToDeviceUnits(9) : item.GetPreferredSize(Size.Empty).Height; |
| 30 | item.AutoSize = false; |
| 31 | item.Size = new Size(width - Padding.Horizontal, height); |
| 32 | } |
| 33 | MinimumSize = new Size(width, 0); |
| 34 | } |
| 35 | } |