* UILine:准备增加线两端样式

This commit is contained in:
Sunny 2021-10-13 23:29:59 +08:00
parent 58528d1d7b
commit 6f1f601399
4 changed files with 41 additions and 6 deletions

Binary file not shown.

Binary file not shown.

View File

@ -43,7 +43,8 @@
<HintPath>..\Bin\net40\SunnyUI.dll</HintPath> <HintPath>..\Bin\net40\SunnyUI.dll</HintPath>
</Reference> </Reference>
<Reference Include="SunnyUI.Common, Version=3.0.8.0, Culture=neutral, PublicKeyToken=5a271fb7ba597231, processorArchitecture=MSIL"> <Reference Include="SunnyUI.Common, Version=3.0.8.0, Culture=neutral, PublicKeyToken=5a271fb7ba597231, processorArchitecture=MSIL">
<HintPath>..\packages\SunnyUI.Common.3.0.8\lib\net40\SunnyUI.Common.dll</HintPath> <SpecificVersion>False</SpecificVersion>
<HintPath>..\Bin\net40\SunnyUI.Common.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />

View File

@ -99,22 +99,56 @@ namespace Sunny.UI
set => SetForeColor(value); set => SetForeColor(value);
} }
private LineCap startCap = LineCap.Flat;
[DefaultValue(LineCap.Flat), Category("SunnyUI")]
public LineCap StartCap
{
get => startCap;
set
{
startCap = value;
Invalidate();
}
}
private LineCap endCap = LineCap.Flat;
[DefaultValue(LineCap.Flat), Category("SunnyUI")]
public LineCap EndCap
{
get => endCap;
set
{
endCap = value;
Invalidate();
}
}
protected override void OnPaintRect(Graphics g, GraphicsPath path) protected override void OnPaintRect(Graphics g, GraphicsPath path)
{ {
Pen pen = new Pen(rectColor, lineSize);
pen.StartCap = StartCap;
pen.EndCap = EndCap;
g.Smooth();
if (Direction == LineDirection.Horizontal) if (Direction == LineDirection.Horizontal)
{ {
int top = (Height - lineSize) / 2; int top = (Height - lineSize) / 2;
g.FillRectangle(rectColor, Padding.Left, top, Width - Padding.Left - Padding.Right, lineSize); g.DrawLine(pen, Padding.Left, top, Width - Padding.Left - Padding.Right, top);
g.DrawLine(Color.FromArgb(50, fillColor), Padding.Left, top + lineSize, Width - Padding.Right - 1, top + lineSize);
} }
else else
{ {
int left = (Width - lineSize) / 2; int left = (Width - lineSize) / 2;
g.FillRectangle(rectColor, left, Padding.Top, lineSize, Height - Padding.Top - Padding.Bottom); g.DrawLine(pen, left, Padding.Top, left, Height - Padding.Top - Padding.Bottom);
g.DrawLine(Color.FromArgb(50, fillColor), left + lineSize, Padding.Top, left + lineSize, Height - Padding.Bottom - 1);
} }
g.Smooth(false);
pen.Dispose();
} }
private int textInterval = 10; private int textInterval = 10;
[DefaultValue(10)] [DefaultValue(10)]
@ -131,7 +165,7 @@ namespace Sunny.UI
protected override void OnPaintFore(Graphics g, GraphicsPath path) protected override void OnPaintFore(Graphics g, GraphicsPath path)
{ {
if (Text.IsNullOrEmpty()) return; if (string.IsNullOrEmpty(Text)) return;
SizeF sf = g.MeasureString(Text, Font); SizeF sf = g.MeasureString(Text, Font);