* UIPanel: 增加透明度

This commit is contained in:
Sunny 2024-11-19 09:40:43 +08:00
parent 3c2ba689eb
commit 7e6ee8e98b

View File

@ -27,10 +27,12 @@
* 2022-02-16: V3.1.1
* 2022-03-19: V3.1.1
* 2022-06-10: V3.1.9
* 2024-11-19: V3.7.2
******************************************************************************/
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace Sunny.UI
{
@ -40,7 +42,7 @@ namespace Sunny.UI
{
InitializeComponent();
base.Font = UIStyles.Font();
base.MinimumSize = new System.Drawing.Size(1, 1);
base.MinimumSize = new Size(1, 1);
showText = true;
SetStyleFlags(true, false, true);
}
@ -98,5 +100,37 @@ namespace Sunny.UI
AfterSetForeReadOnlyColor(color);
Invalidate();
}
private byte _opacity = 255;
[Description("透明度"), Category("SunnyUI")]
[DefaultValue(typeof(byte), "255")]
public byte Opacity
{
get => _opacity;
set
{
if (_opacity != value)
{
_opacity = value;
Invalidate();
}
}
}
protected override void OnPaintFill(Graphics g, GraphicsPath path)
{
if (_opacity == 255)
{
base.OnPaintFill(g, path);
}
else
{
var color = GetFillColor().Alpha(_opacity);
if (RadiusSides == UICornerRadiusSides.None || Radius == 0)
g.Clear(color);
else
g.FillPath(color, path);
}
}
}
}