From 5d9e0a6f5308cd1aa79e2cd5187af9ef5b6ebf3d Mon Sep 17 00:00:00 2001 From: Sunny Date: Thu, 26 Dec 2024 21:32:53 +0800 Subject: [PATCH] =?UTF-8?q?+=20UIMenuButton:=20=E5=A2=9E=E5=8A=A0=E4=B8=8B?= =?UTF-8?q?=E6=8B=89=E8=8F=9C=E5=8D=95=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Controls/UIMenuButton.cs | 65 ++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 SunnyUI/Controls/UIMenuButton.cs diff --git a/SunnyUI/Controls/UIMenuButton.cs b/SunnyUI/Controls/UIMenuButton.cs new file mode 100644 index 00000000..ef149089 --- /dev/null +++ b/SunnyUI/Controls/UIMenuButton.cs @@ -0,0 +1,65 @@ +/****************************************************************************** + * SunnyUI 开源控件库、工具类库、扩展类库、多页面开发框架。 + * CopyRight (C) 2012-2024 ShenYongHua(沈永华). + * QQ群:56829229 QQ:17612584 EMail:SunnyUI@QQ.Com + * + * Blog: https://www.cnblogs.com/yhuse + * Gitee: https://gitee.com/yhuse/SunnyUI + * GitHub: https://github.com/yhuse/SunnyUI + * + * SunnyUI.dll can be used for free under the GPL-3.0 license. + * If you use this code, please keep this note. + * 如果您使用此代码,请保留此说明。 + ****************************************************************************** + * 文件名称: UIMenuButton.cs + * 文件说明: 下拉菜单按钮 + * 当前版本: V3.8 + * 创建日期: 2024-12-16 + * + * 2024-12-16: V3.8.0 增加文件说明 +******************************************************************************/ + +using System.ComponentModel; +using System.Drawing; +using System.Windows.Forms; + +namespace Sunny.UI +{ + [DefaultEvent("Click")] + [DefaultProperty("Text")] + public class UIMenuButton : UISymbolButton + { + private bool _showDropArrow = true; + public UIContextMenuStrip Menu { get; set; } + + protected override void OnMouseClick(MouseEventArgs e) + { + base.OnMouseClick(e); + Menu?.Show(this, 0, Height); + } + + protected override void OnPaint(PaintEventArgs e) + { + base.OnPaint(e); + if (ShowDropArrow) + { + e.Graphics.DrawFontImage(61703, SymbolSize, GetForeColor(), new Rectangle(Width - SymbolSize - 4, 0, SymbolSize, Height)); + } + } + + /// + /// 字体图标 + /// + [DefaultValue(true)] + [Description("显示下拉按钮"), Category("SunnyUI")] + public bool ShowDropArrow + { + get => _showDropArrow; + set + { + _showDropArrow = value; + Invalidate(); + } + } + } +}