// COPYRIGHT (C) Tom. ALL RIGHTS RESERVED. // THE AntdUI PROJECT IS AN WINFORM LIBRARY LICENSED UNDER THE Apache-2.0 License. // LICENSED UNDER THE Apache License, VERSION 2.0 (THE "License") // YOU MAY NOT USE THIS FILE EXCEPT IN COMPLIANCE WITH THE License. // YOU MAY OBTAIN A COPY OF THE LICENSE AT // // http://www.apache.org/licenses/LICENSE-2.0 // // UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING, SOFTWARE // DISTRIBUTED UNDER THE LICENSE IS DISTRIBUTED ON AN "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. // SEE THE LICENSE FOR THE SPECIFIC LANGUAGE GOVERNING PERMISSIONS AND // LIMITATIONS UNDER THE License. // GITEE: https://gitee.com/antdui/AntdUI // GITHUB: https://github.com/AntdUI/AntdUI // CSDN: https://blog.csdn.net/v_132 // QQ: 17379620 using System; using System.Drawing; using System.Windows.Forms; namespace AntdUI { /// /// 右键菜单 /// public static class ContextMenuStrip { /// /// ContextMenuStrip 右键菜单 /// /// 所属控件 /// 点击回调 /// 内容 public static Form? open(Control control, Action call, IContextMenuStripItem[] items, int sleep = 0) { return open(new Config(control, call, items, sleep)); } /// /// ContextMenuStrip 右键菜单 /// /// 所属控件 /// 托盘 /// 点击回调 /// 内容 public static Form? open(Control control, NotifyIcon notifyIcon, Action call, IContextMenuStripItem[] items, int sleep = 0) { return open(new Config(control, call, items, sleep) { TopMost = true, Align = TAlign.TL }); } /// /// ContextMenuStrip 右键菜单 /// /// 配置 public static Form? open(this Config config) { if (config.Control.IsHandleCreated) { if (config.Control.InvokeRequired) { Form? form = null; config.Control.Invoke(new Action(() => { form = open(config); })); return form; } var frm = new LayeredFormContextMenuStrip(config); frm.Show(config.Control); return frm; } return null; } /// /// 配置 /// public class Config { public Config(Control control, Action call, IContextMenuStripItem[] items, int sleep = 0) { Control = control; Call = call; Items = items; CallSleep = sleep; } /// /// 所属控件 /// public Control Control { get; set; } /// /// 菜单内容 /// public IContextMenuStripItem[] Items { get; set; } /// /// 字体 /// public Font? Font { get; set; } /// /// 圆角 /// public int Radius { get; set; } = 6; /// /// 是否置顶 /// public bool TopMost { get; set; } /// /// 延迟回调 /// public int CallSleep { get; set; } /// /// 是否抢占焦点 /// public bool UFocus { get; set; } /// /// 坐标 /// public Point? Location { get; set; } /// /// 方向 /// public TAlign Align { get; set; } = TAlign.BR; /// /// 点击回调 /// public Action Call { get; set; } } } /// /// 右键菜单项 /// public class ContextMenuStripItem : IContextMenuStripItem { /// /// 右键菜单项 /// /// 文本 public ContextMenuStripItem(string text) { Text = text; } /// /// 右键菜单项 /// /// 文本 /// 子文本 public ContextMenuStripItem(string text, string subtext) { Text = text; SubText = subtext; } /// /// 文本 /// public string Text { get; set; } /// /// 子文本 /// public string? SubText { get; set; } /// /// 文字颜色 /// public Color? Fore { get; set; } /// /// 图标 /// public Bitmap? Icon { get; set; } /// /// 图标SVG /// public string? IconSvg { get; set; } /// /// 使能 /// public bool Enabled { get; set; } = true; /// /// 选中 /// public bool Checked { get; set; } /// /// 子项 /// public IContextMenuStripItem[]? Sub { get; set; } /// /// 用户定义数据 /// public object? Tag { get; set; } } /// /// 右键菜单分割项 /// public class ContextMenuStripItemDivider : IContextMenuStripItem { } public class IContextMenuStripItem { } }