SVN r865
SVN-Revision: r865
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
/******************************
|
||||
* Menu_ItemNew 1.2.2 - fixed badge & hover
|
||||
******************************/
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using Lskj.Business;
|
||||
using Lskj.Business.Impl;
|
||||
|
||||
namespace Lskj.Main.Control
|
||||
{
|
||||
public partial class Menu_ItemNew : UserControl
|
||||
{
|
||||
/* —— 样式 —— */
|
||||
private readonly Color _hoverBorder = Color.FromArgb(211, 211, 211); // 淡灰色
|
||||
private readonly Color _hoverBack = Color.White;
|
||||
private readonly Color _normalBack = Color.FromArgb(240, 240, 240);
|
||||
|
||||
/* —— 状态 —— */
|
||||
private bool _isHover;
|
||||
private Image _imgDefault, _imgHover;
|
||||
private int _radius = 10;
|
||||
|
||||
/* —— 外部信息 —— */
|
||||
public int menuRow;
|
||||
public int menuGroup;
|
||||
public string menuNode;
|
||||
|
||||
public Menu_ItemNew()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
/* 统一绑定悬停事件 */
|
||||
BindHover(this);
|
||||
BindHover(btn_icon);
|
||||
BindHover(lbl_title);
|
||||
BindHover(lbl_sub);
|
||||
BindHover(badgeDot);
|
||||
BindHover(badgeNum);
|
||||
|
||||
/* 统一绑定 Click —— 1 行即可 */
|
||||
BindClick(btn_icon);
|
||||
BindClick(lbl_title);
|
||||
BindClick(lbl_sub);
|
||||
BindClick(badgeDot);
|
||||
}
|
||||
private void BindClick(System.Windows.Forms.Control ctl)
|
||||
{
|
||||
ctl.Click += (s, e) =>
|
||||
{
|
||||
// 直接把 Click 冒泡给 Menu_ItemNew 本身
|
||||
this.OnClick(e); // this 就是 Menu_ItemNew
|
||||
};
|
||||
}
|
||||
|
||||
/* ===== 对外 API ===== */
|
||||
public void SetMenuCaption(string text)
|
||||
{ lbl_title.Text = text; toolTip1.SetToolTip(lbl_title, text); }
|
||||
|
||||
public void SetSubCaption(string text) => lbl_sub.Text = text;
|
||||
|
||||
public void SetMenuImg(Image img)
|
||||
{ _imgDefault = img; btn_icon.BackgroundImage = img; }
|
||||
|
||||
public void SetMenuHoverImg(Image img) => _imgHover = img;
|
||||
|
||||
public void SetMenuNum(int num)
|
||||
{
|
||||
if (SystemInfo.Instance.DisableShowNotify || num < 1)
|
||||
{
|
||||
badgeDot.Visible = false;
|
||||
return;
|
||||
}
|
||||
|
||||
badgeDot.Number = num; // 一行搞定
|
||||
badgeDot.Visible = true;
|
||||
|
||||
RepositionBadge();
|
||||
}
|
||||
|
||||
/* ===== 圆角属性(如需保留) ===== */
|
||||
[Browsable(true), Description("圆角半径(px)")]
|
||||
public int CornerRadius
|
||||
{
|
||||
get => _radius;
|
||||
set { _radius = Math.Max(0, value); Invalidate(); }
|
||||
}
|
||||
|
||||
/* —— 兼容旧写法 —— */
|
||||
public int SetRoundRadius
|
||||
{
|
||||
get => CornerRadius;
|
||||
set => CornerRadius = value;
|
||||
}
|
||||
public Button GetButton() => btn_icon;
|
||||
|
||||
/* ===== 悬停逻辑 ===== */
|
||||
private void HoverEnter(object s, EventArgs e)
|
||||
{
|
||||
if (_isHover) return;
|
||||
_isHover = true;
|
||||
//BackColor = _hoverBack;
|
||||
btn_icon.BackgroundImage = _imgHover ?? _imgDefault;
|
||||
Cursor = Cursors.Hand;
|
||||
Invalidate();
|
||||
}
|
||||
private void HoverLeave(object s, EventArgs e)
|
||||
{
|
||||
if (ClientRectangle.Contains(PointToClient(System.Windows.Forms.Control.MousePosition))) return;
|
||||
_isHover = false;
|
||||
//BackColor = _normalBack;
|
||||
btn_icon.BackgroundImage = _imgDefault;
|
||||
Invalidate();
|
||||
}
|
||||
private void BindHover(System.Windows.Forms.Control ctl)
|
||||
{
|
||||
ctl.MouseEnter += HoverEnter;
|
||||
ctl.MouseLeave += HoverLeave;
|
||||
}
|
||||
|
||||
/* ===== 绘制高亮边框(无圆角) ===== */
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
base.OnPaint(e);
|
||||
if (!_isHover) return;
|
||||
|
||||
var rc = new Rectangle(0, 0, Width - 1, Height - 1);
|
||||
|
||||
Reference in New Issue
Block a user