diff --git a/插件库/Lskj.Control/CircleButton.Designer.cs b/插件库/Lskj.Control/CircleButton.Designer.cs
index 1756505..0ba454e 100644
--- a/插件库/Lskj.Control/CircleButton.Designer.cs
+++ b/插件库/Lskj.Control/CircleButton.Designer.cs
@@ -1,36 +1 @@
-namespace Lskj.Control
-{
- partial class CircleButton
- {
- ///
- /// 必需的设计器变量。
- ///
- private System.ComponentModel.IContainer components = null;
-
- ///
- /// 清理所有正在使用的资源。
- ///
- /// 如果应释放托管资源,为 true;否则为 false。
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
-
- #region 组件设计器生成的代码
-
- ///
- /// 设计器支持所需的方法 - 不要
- /// 使用代码编辑器修改此方法的内容。
- ///
- private void InitializeComponent()
- {
- components = new System.ComponentModel.Container();
- }
-
- #endregion
- }
-}
+namespace Lskj.Cont
\ No newline at end of file
diff --git a/插件库/Lskj.Control/CircleButton.cs b/插件库/Lskj.Control/CircleButton.cs
index 31b147a..d796831 100644
--- a/插件库/Lskj.Control/CircleButton.cs
+++ b/插件库/Lskj.Control/CircleButton.cs
@@ -1,179 +1,123 @@
-using System;
-using System.Collections.Generic;
+/***************************************************
+ * CircleButton 2.0 · Red badge with built-in number
+ * Author : Gong Yuchao (2017-08-16), rev 2025-07-17
+ ***************************************************/
+using System;
using System.ComponentModel;
using System.Diagnostics;
-using System.Linq;
-using System.Text;
-using System.Windows.Forms;
using System.Drawing;
-using Lskj.Business.Impl;
+using System.Drawing.Drawing2D;
+using System.Windows.Forms;
namespace Lskj.Control
{
- public partial class CircleButton : Button
+ [DefaultEvent(nameof(Click))]
+ public partial class CircleButton : Button
{
- private int radius;//半径
+ /* ───────── 可调属性 ───────── */
- //圆形按钮的半径属性
- [CategoryAttribute("布局"), BrowsableAttribute(true), ReadOnlyAttribute(false)]
+ private int _radius = 18 / 2; // 直径 18px
+ [Category("布局"), Description("圆点半径(px)")]
public int Radius
{
- set
- {
- radius = value;
- this.Height = this.Width = Radius;
- }
- get
- {
- return radius;
- }
+ get => _radius;
+ set { _radius = Math.Max(4, value); SyncSize(); }
}
- private Image imageEnter;
- [CategoryAttribute("外观"), BrowsableAttribute(true), ReadOnlyAttribute(false)]
- public Image ImageEnter
+ private int _number;
+ [Category("数据"), Description("角标数字(>99 显示 99)")]
+ public int Number
{
- set
- {
- imageEnter = value;
- }
- get
- {
- return imageEnter;
- }
+ get => _number;
+ set { _number = Math.Max(0, value); Invalidate(); }
}
- private Image imageNormal;
- [CategoryAttribute("外观"), BrowsableAttribute(true), ReadOnlyAttribute(false)]
+ [Category("外观"), Description("普通状态图(可省略)")]
public Image ImageNormal
{
- set
- {
- imageNormal = value;
- BackgroundImage = imageNormal;
- }
- get
- {
- return imageNormal;
- }
+ get => _imgNormal;
+ set { _imgNormal = value; if (!_hover) BackgroundImage = value; }
}
+ private Image _imgNormal;
- //以下代码用于在VS中隐藏BackgroundImage属性,使得只能通过Diameter设置Height和Width
- [BrowsableAttribute(false)]
- public new Image BackgroundImage
- {
- get
- {
- return base.BackgroundImage;
- }
- set
- {
- base.BackgroundImage = value;
+ [Category("外观"), Description("悬停状态图(可省略)")]
+ public Image ImageHover { get; set; }
- }
- }
+ [Category("外观"), Description("边框颜色(透明=无)")]
+ public Color BorderColor { get; set; } = Color.Transparent;
- //以下代码用于在VS中隐藏Size属性,使得只能通过Diameter设置Height和Width
- [BrowsableAttribute(false)]
- public new Size Size
- {
- get
- {
- return base.Size;
- }
- set
- {
- base.Size = value;
+ [Category("外观"), Description("边框粗细(px)")]
+ public float BorderThickness { get; set; } = 1f;
- }
- }
+ /* ───────── 状态 ───────── */
+ private bool _hover;
+ /* ───────── ctor ───────── */
public CircleButton()
{
- Radius = 64;
- this.Height = this.Width = Radius;
- this.FlatStyle = FlatStyle.Flat;
- this.FlatAppearance.BorderSize = 0;
- this.BackgroundImage = imageEnter;
- this.BackgroundImageLayout = ImageLayout.Stretch;
+ SetStyle(ControlStyles.AllPaintingInWmPaint |
+ ControlStyles.UserPaint |
+ ControlStyles.OptimizedDoubleBuffer, true);
+
+ FlatStyle = FlatStyle.Flat;
+ FlatAppearance.BorderSize = 0;
+ BackColor = Color.Red;
+ ForeColor = Color.White;
+
+ SyncSize();
+
+ MouseEnter += (_, __) => SetHover(true);
+ MouseLeave += (_, __) => SetHover(false);
}
- //重写OnPaint
- protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
+ /* ───────── 重绘 ───────── */
+ protected override void OnResize(EventArgs e)
{
- try {
- base.OnPaint(e);
- System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
- path.AddEllipse(0, 0, Radius, Radius);
- this.Region = new Region(path);
- }
- catch (Exception ex)
+ base.OnResize(e);
+ UpdateRegion();
+ }
+
+ protected override void OnPaint(PaintEventArgs e)
+ {
+ base.OnPaint(e);
+ e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
+
+ // ① 画圆填充
+ using (SolidBrush br = new SolidBrush(BackColor))
{
- string Message = ErrorMessage.PromptErrorMessage(ex);
- MessageUtil.Show(Message,ex.Message);
- }
-
- }
+ e.Graphics.FillEllipse(br, 0, 0, Width, Height);
+ }
- //重写OnMouseEnter
- //protected override void OnMouseEnter(EventArgs e)
- //{
- // Graphics g = this.CreateGraphics();
- // g.DrawEllipse(new Pen(Color.Blue), 0, 0, this.Width, this.Height);
- // g.Dispose();
- //}
-
- //重写OnSizeChanged
- protected override void OnSizeChanged(EventArgs e)
- {
- try {
- base.OnSizeChanged(e);
- if (Height != Radius)
+ // ② 画边框(可选)
+ if (BorderColor.A > 0 && BorderThickness > 0)
+ {
+ using (Pen pen = new Pen(BorderColor, BorderThickness))
{
- Radius = Width = Height;
- }
- else if (Width != Radius)
- {
- Radius = Height = Width;
+ Rectangle rc = new Rectangle(
+ (int)(BorderThickness / 2),
+ (int)(BorderThickness / 2),
+ Width - (int)BorderThickness,
+ Height - (int)BorderThickness);
+ e.Graphics.DrawEllipse(pen, rc);
}
}
- catch (Exception ex)
+
+ // ③ 绘制数字
+ if (_number > 0)
{
- string Message = ErrorMessage.PromptErrorMessage(ex);
- MessageUtil.Show(Message,ex.Message);
- }
-
-
- }
-
- //重写OnMouseEnter
- protected override void OnMouseEnter(EventArgs e)
- {
- try {
- base.OnMouseEnter(e);
- BackgroundImage = ImageEnter;
+ string txt = _number > 99 ? "99" : _number.ToString();
+ using (SolidBrush fb = new SolidBrush(ForeColor))
+ using (StringFormat sf = new StringFormat
+ {
+ Alignment = StringAlignment.Center,
+ LineAlignment = StringAlignment.Center
+ })
+ {
+ e.Graphics.DrawString(txt, Font, fb,
+ new RectangleF(0, 0, Width, Height), sf);
+ }
}
- catch (Exception ex)
- {
- string Message = ErrorMessage.PromptErrorMessage(ex);
- MessageUtil.Show(Message,ex.Message);
- }
-
}
- //重写OnMouseLeave
- protected override void OnMouseLeave(EventArgs e)
- {
- try {
- base.OnMouseLeave(e);
- BackgroundImage = ImageNormal;
- }
- catch (Exception ex)
- {
- string Message = ErrorMessage.PromptErrorMessage(ex);
- MessageUtil.Show(Message,ex.Message);
- }
-
- }
- }
-}
+ /* ───────── 私有助手 ───────── */
+ private void SetHover(
\ No newline at end of file