123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- using System.Windows.Controls.Primitives;
- namespace System.Windows.Forms
- {
- public partial class ContextMenuStrip
- {
- private class PopupWrapper : IPopupWrapper
- {
- private CustomControls.ContextMenuStrip menu;
- private ContextMenuStrip owner;
- public bool IsOpen
- {
- get => menu.IsOpen;
- set
- {
- menu.EnableQuickAccessToolbar = owner.EnableQuickAccessToolbar;
- menu.SetIsOpen(value);
- }
- }
- public PlacementMode Placement { get => menu.Placement; set => menu.Placement = value; }
- public UIElement PlacementTarget { get => menu.PlacementTarget; set => menu.PlacementTarget = value; }
- public double HorizontalOffset { get => menu.HorizontalOffset; set => menu.HorizontalOffset = value; }
- public double VerticalOffset { get => menu.VerticalOffset; set => menu.VerticalOffset = value; }
- public event EventHandler Opened;
- public event EventHandler Closed;
- public void AddChild(Control child) => menu.Items.Add(child.control);
- public void RemoveChild(Control child) => menu.Items.Remove(child.control);
- public void SetChildIndex(Control child, int index) => menu.Items.Insert(index, child.control);
- public void ApplyStyle(ToolStripProfessionalRenderer r)
- {
- menu.Resources["Menu.Static.Background"] = r.MenuStaticBackground;
- menu.Resources["Menu.Static.Border"] = r.MenuStaticBorder;
- menu.Resources["Menu.Static.Foreground"] = r.Foreground;
- menu.Resources["Menu.Disabled.Foreground"] = r.DisabledForeground;
- menu.Resources["Menu.Margin.Background"] = r.MenuMarginBackground;
- menu.Resources["Menu.QAT.Background"] = r.MenuQATBackground;
- }
- public void FixupDpi()
- {
- // In case dpi was changed during app run, the menu may not be updated yet.
- // It will show odd font size at the first open. Correct that by supplying correct dpi from PlacementTarget object.
- if (menu.PlacementTarget != null)
- Helper.SetFont(menu, Helper.GetDpiScale(menu.PlacementTarget), owner.Font);
- else
- Helper.SetFont(menu, owner.Font);
- }
- public PopupWrapper(ContextMenuStrip owner)
- {
- menu = new();
- this.owner = owner;
- menu.Tag = owner;
- menu.Opened += (s, e) => Opened?.Invoke(this, EventArgs.Empty);
- menu.Closed += (s, e) => Closed?.Invoke(this, EventArgs.Empty);
- }
- }
- }
- }
|