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; /// /// 所在行数 /// public int menuRow; /// /// 所在子菜单 /// public string menuNode; public Menu_Item() { InitializeComponent(); } public Button GetButton() { return this.btn_item_img; } /// /// 设置模块显示名称 /// public void SetMenuCaption(string text) { this.btn_item_title.Text = text; this.toolTip1.SetToolTip(this.btn_item_title, text); } /// /// 设置背景图标 /// /// public void SetMenuImg(Image img) { this.defaultImg = img; this.btn_item_img.BackgroundImage = img; this.btn_item_img.BackgroundImageLayout = ImageLayout.Center; } /// /// 设置选中背景图标 /// /// public void SetMenuHoverImg(Image img) { this.hoverImg = img; } /// /// 选中背景图片 /// /// /// 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; } /// /// 还原背景 /// /// /// 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; // 圆角弧度 /// 圆角弧度(0为不要圆角) [Browsable(true)] [Description("圆角弧度(0为不要圆角)")] public int SetRoundRadius { get { return _Radius; } set { if (value < 0) { _Radius = 0; } else { _Radius = value; } base.Refresh(); } } /// /// 重绘圆角 /// /// /// 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); } } } }