+ UIMenuButton: 增加下拉菜单按钮

This commit is contained in:
Sunny 2024-12-26 21:32:53 +08:00
parent 65a35f5bad
commit 5d9e0a6f53

View File

@ -0,0 +1,65 @@
/******************************************************************************
* SunnyUI
* CopyRight (C) 2012-2024 ShenYongHua().
* QQ群56829229 QQ17612584 EMailSunnyUI@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));
}
}
/// <summary>
/// 字体图标
/// </summary>
[DefaultValue(true)]
[Description("显示下拉按钮"), Category("SunnyUI")]
public bool ShowDropArrow
{
get => _showDropArrow;
set
{
_showDropArrow = value;
Invalidate();
}
}
}
}