SVN r864
SVN-Revision: r864
This commit is contained in:
+1
-36
@@ -1,36 +1 @@
|
|||||||
namespace Lskj.Control
|
namespace Lskj.Cont
|
||||||
{
|
|
||||||
partial class CircleButton
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 必需的设计器变量。
|
|
||||||
/// </summary>
|
|
||||||
private System.ComponentModel.IContainer components = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 清理所有正在使用的资源。
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing && (components != null))
|
|
||||||
{
|
|
||||||
components.Dispose();
|
|
||||||
}
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region 组件设计器生成的代码
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 设计器支持所需的方法 - 不要
|
|
||||||
/// 使用代码编辑器修改此方法的内容。
|
|
||||||
/// </summary>
|
|
||||||
private void InitializeComponent()
|
|
||||||
{
|
|
||||||
components = new System.ComponentModel.Container();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using Lskj.Business.Impl;
|
using System.Drawing.Drawing2D;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace Lskj.Control
|
namespace Lskj.Control
|
||||||
{
|
{
|
||||||
public partial class CircleButton : Button
|
[DefaultEvent(nameof(Click))]
|
||||||
|
public partial class CircleButton : Button
|
||||||
{
|
{
|
||||||
private int radius;//半径
|
/* ───────── 可调属性 ───────── */
|
||||||
|
|
||||||
//圆形按钮的半径属性
|
private int _radius = 18 / 2; // 直径 18px
|
||||||
[CategoryAttribute("布局"), BrowsableAttribute(true), ReadOnlyAttribute(false)]
|
[Category("布局"), Description("圆点半径(px)")]
|
||||||
public int Radius
|
public int Radius
|
||||||
{
|
{
|
||||||
set
|
get => _radius;
|
||||||
{
|
set { _radius = Math.Max(4, value); SyncSize(); }
|
||||||
radius = value;
|
|
||||||
this.Height = this.Width = Radius;
|
|
||||||
}
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return radius;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Image imageEnter;
|
private int _number;
|
||||||
[CategoryAttribute("外观"), BrowsableAttribute(true), ReadOnlyAttribute(false)]
|
[Category("数据"), Description("角标数字(>99 显示 99)")]
|
||||||
public Image ImageEnter
|
public int Number
|
||||||
{
|
{
|
||||||
set
|
get => _number;
|
||||||
{
|
set { _number = Math.Max(0, value); Invalidate(); }
|
||||||
imageEnter = value;
|
|
||||||
}
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return imageEnter;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Image imageNormal;
|
[Category("外观"), Description("普通状态图(可省略)")]
|
||||||
[CategoryAttribute("外观"), BrowsableAttribute(true), ReadOnlyAttribute(false)]
|
|
||||||
public Image ImageNormal
|
public Image ImageNormal
|
||||||
{
|
{
|
||||||
set
|
get => _imgNormal;
|
||||||
{
|
set { _imgNormal = value; if (!_hover) BackgroundImage = value; }
|
||||||
imageNormal = value;
|
|
||||||
BackgroundImage = imageNormal;
|
|
||||||
}
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return imageNormal;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
private Image _imgNormal;
|
||||||
|
|
||||||
//以下代码用于在VS中隐藏BackgroundImage属性,使得只能通过Diameter设置Height和Width
|
[Category("外观"), Description("悬停状态图(可省略)")]
|
||||||
[BrowsableAttribute(false)]
|
public Image ImageHover { get; set; }
|
||||||
public new Image BackgroundImage
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return base.BackgroundImage;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
base.BackgroundImage = value;
|
|
||||||
|
|
||||||
}
|
[Category("外观"), Description("边框颜色(透明=无)")]
|
||||||
}
|
public Color BorderColor { get; set; } = Color.Transparent;
|
||||||
|
|
||||||
//以下代码用于在VS中隐藏Size属性,使得只能通过Diameter设置Height和Width
|
[Category("外观"), Description("边框粗细(px)")]
|
||||||
[BrowsableAttribute(false)]
|
public float BorderThickness { get; set; } = 1f;
|
||||||
public new Size Size
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return base.Size;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
base.Size = value;
|
|
||||||
|
|
||||||
}
|
/* ───────── 状态 ───────── */
|
||||||
}
|
private bool _hover;
|
||||||
|
|
||||||
|
/* ───────── ctor ───────── */
|
||||||
public CircleButton()
|
public CircleButton()
|
||||||
{
|
{
|
||||||
Radius = 64;
|
SetStyle(ControlStyles.AllPaintingInWmPaint |
|
||||||
this.Height = this.Width = Radius;
|
ControlStyles.UserPaint |
|
||||||
this.FlatStyle = FlatStyle.Flat;
|
ControlStyles.OptimizedDoubleBuffer, true);
|
||||||
this.FlatAppearance.BorderSize = 0;
|
|
||||||
this.BackgroundImage = imageEnter;
|
FlatStyle = FlatStyle.Flat;
|
||||||
this.BackgroundImageLayout = ImageLayout.Stretch;
|
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.OnResize(e);
|
||||||
base.OnPaint(e);
|
UpdateRegion();
|
||||||
System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
|
}
|
||||||
path.AddEllipse(0, 0, Radius, Radius);
|
|
||||||
this.Region = new Region(path);
|
protected override void OnPaint(PaintEventArgs e)
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
base.OnPaint(e);
|
||||||
|
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
||||||
|
|
||||||
|
// ① 画圆填充
|
||||||
|
using (SolidBrush br = new SolidBrush(BackColor))
|
||||||
{
|
{
|
||||||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
e.Graphics.FillEllipse(br, 0, 0, Width, Height);
|
||||||
MessageUtil.Show(Message,ex.Message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
// ② 画边框(可选)
|
||||||
|
if (BorderColor.A > 0 && BorderThickness > 0)
|
||||||
//重写OnMouseEnter
|
{
|
||||||
//protected override void OnMouseEnter(EventArgs e)
|
using (Pen pen = new Pen(BorderColor, BorderThickness))
|
||||||
//{
|
|
||||||
// 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)
|
|
||||||
{
|
{
|
||||||
Radius = Width = Height;
|
Rectangle rc = new Rectangle(
|
||||||
}
|
(int)(BorderThickness / 2),
|
||||||
else if (Width != Radius)
|
(int)(BorderThickness / 2),
|
||||||
{
|
Width - (int)BorderThickness,
|
||||||
Radius = Height = Width;
|
Height - (int)BorderThickness);
|
||||||
|
e.Graphics.DrawEllipse(pen, rc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
|
// ③ 绘制数字
|
||||||
|
if (_number > 0)
|
||||||
{
|
{
|
||||||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
string txt = _number > 99 ? "99" : _number.ToString();
|
||||||
MessageUtil.Show(Message,ex.Message);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//重写OnMouseEnter
|
/* ───────── 私有助手 ───────── */
|
||||||
protected override void OnMouseEnter(EventArgs e)
|
private void SetHover(
|
||||||
{
|
|
||||||
try {
|
|
||||||
base.OnMouseEnter(e);
|
|
||||||
BackgroundImage = ImageEnter;
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user