Files
2026-07-10 15:25:05 +08:00

133 lines
4.1 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Lskj.Main
{
public partial class Menu_Item : UserControl
{
private Image defaultImg, hoverImg;
/// <summary>
/// 所在行数
/// </summary>
public int menuRow;
/// <summary>
/// 所在子菜单
/// </summary>
public string menuNode;
public Menu_Item()
{
InitializeComponent();
}
public Button GetButton()
{
return this.btn_item_img;
}
/// <summary>
/// 设置模块显示名称
/// </summary>
public void SetMenuCaption(string text)
{
this.btn_item_title.Text = text;
this.toolTip1.SetToolTip(this.btn_item_title, text);
}
/// <summary>
/// 设置背景图标
/// </summary>
/// <param name="img"></param>
public void SetMenuImg(Image img)
{
this.defaultImg = img;
this.btn_item_img.BackgroundImage = img;
this.btn_item_img.BackgroundImageLayout = ImageLayout.Center;
}
/// <summary>
/// 设置选中背景图标
/// </summary>
/// <param name="img"></param>
public void SetMenuHoverImg(Image img)
{
this.hoverImg = img;
}
/// <summary>
/// 选中背景图片
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_item_img_MouseMove(object sender, MouseEventArgs e)
{
//(sender as Button).BackgroundImage = hoverImg;
//(sender as Button).BackgroundImageLayout = ImageLayout.Center;
this.BackColor = Color.White;
this.Cursor = Cursors.Hand;
}
/// <summary>
/// 还原背景
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_item_img_MouseLeave(object sender, EventArgs e)
{
//(sender as Button).BackgroundImage = defaultImg;
//this.BackColor = Color.FromArgb(240, 240, 240);
this.BackColor = Color.Transparent;
}
// 圆角
// ===============================================================================================
private int _Radius; // 圆角弧度
/// <summary>圆角弧度(0为不要圆角)</summary>
[Browsable(true)]
[Description("圆角弧度(0为不要圆角)")]
public int SetRoundRadius
{
get
{
return _Radius;
}
set
{
if (value < 0) { _Radius = 0; }
else { _Radius = value; }
base.Refresh();
}
}
/// <summary>
/// 重绘圆角
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Menu_Item_Paint(object sender, PaintEventArgs e)
{
System.Drawing.Drawing2D.GraphicsPath oPath = new System.Drawing.Drawing2D.GraphicsPath();
int x = 0;
int y = 0;
int thisWidth = this.Width;
int thisHeight = this.Height;
int angle = _Radius;
if (angle > 0)
{
System.Drawing.Graphics g = CreateGraphics();
oPath.AddArc(x, y, angle, angle, 180, 90); // 左上角
oPath.AddArc(thisWidth - angle, y, angle, angle, 270, 90); // 右上角
oPath.AddArc(thisWidth - angle, thisHeight - angle, angle, angle, 0, 90); // 右下角
oPath.AddArc(x, thisHeight - angle, angle, angle, 90, 90); // 左下角
oPath.CloseAllFigures();
Region = new System.Drawing.Region(oPath);
}
}
}
}