* UIProcessBar: 增加垂直方向的进度显示

This commit is contained in:
Sunny 2021-08-07 16:49:55 +08:00
parent 281cfbfd62
commit 1d49066eb0
10 changed files with 95 additions and 28 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -20,7 +20,7 @@
value++; value++;
uiTrackBar2.Value = uiTrackBar1.Value = value; uiTrackBar2.Value = uiTrackBar1.Value = value;
uiProcessBar2.Value = uiProcessBar1.Value = value; uiProcessBar2.Value = uiProcessBar1.Value = value;
uiRoundProcess2.Value = uiRoundProcess1.Value = value; uiProcessBar3.Value = uiRoundProcess2.Value = uiRoundProcess1.Value = value;
} }
} }
} }

View File

@ -52,6 +52,8 @@ namespace Sunny.UI.Demo
this.uiLine3 = new Sunny.UI.UILine(); this.uiLine3 = new Sunny.UI.UILine();
this.uiProcessBar1 = new Sunny.UI.UIProcessBar(); this.uiProcessBar1 = new Sunny.UI.UIProcessBar();
this.timer1 = new System.Windows.Forms.Timer(this.components); this.timer1 = new System.Windows.Forms.Timer(this.components);
this.uiProcessBar3 = new Sunny.UI.UIProcessBar();
this.uiLine6 = new Sunny.UI.UILine();
this.SuspendLayout(); this.SuspendLayout();
// //
// uiTrackBar8 // uiTrackBar8
@ -147,7 +149,7 @@ namespace Sunny.UI.Demo
this.uiLine2.Location = new System.Drawing.Point(29, 287); this.uiLine2.Location = new System.Drawing.Point(29, 287);
this.uiLine2.MinimumSize = new System.Drawing.Size(16, 16); this.uiLine2.MinimumSize = new System.Drawing.Size(16, 16);
this.uiLine2.Name = "uiLine2"; this.uiLine2.Name = "uiLine2";
this.uiLine2.Size = new System.Drawing.Size(319, 20); this.uiLine2.Size = new System.Drawing.Size(440, 20);
this.uiLine2.TabIndex = 95; this.uiLine2.TabIndex = 95;
this.uiLine2.Text = "UIBreadcrumb"; this.uiLine2.Text = "UIBreadcrumb";
this.uiLine2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; this.uiLine2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@ -211,7 +213,6 @@ namespace Sunny.UI.Demo
// //
// uiProcessBar2 // uiProcessBar2
// //
this.uiProcessBar2.DecimalCount = 1;
this.uiProcessBar2.Font = new System.Drawing.Font("微软雅黑", 12F); this.uiProcessBar2.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiProcessBar2.Location = new System.Drawing.Point(30, 123); this.uiProcessBar2.Location = new System.Drawing.Point(30, 123);
this.uiProcessBar2.MinimumSize = new System.Drawing.Size(70, 1); this.uiProcessBar2.MinimumSize = new System.Drawing.Size(70, 1);
@ -248,7 +249,7 @@ namespace Sunny.UI.Demo
this.uiLine5.Location = new System.Drawing.Point(28, 369); this.uiLine5.Location = new System.Drawing.Point(28, 369);
this.uiLine5.MinimumSize = new System.Drawing.Size(16, 16); this.uiLine5.MinimumSize = new System.Drawing.Size(16, 16);
this.uiLine5.Name = "uiLine5"; this.uiLine5.Name = "uiLine5";
this.uiLine5.Size = new System.Drawing.Size(672, 20); this.uiLine5.Size = new System.Drawing.Size(441, 20);
this.uiLine5.TabIndex = 87; this.uiLine5.TabIndex = 87;
this.uiLine5.Text = "UITrackBar"; this.uiLine5.Text = "UITrackBar";
this.uiLine5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; this.uiLine5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@ -298,25 +299,47 @@ namespace Sunny.UI.Demo
// //
// uiProcessBar1 // uiProcessBar1
// //
this.uiProcessBar1.DecimalCount = 1;
this.uiProcessBar1.Font = new System.Drawing.Font("微软雅黑", 12F); this.uiProcessBar1.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiProcessBar1.Location = new System.Drawing.Point(30, 88); this.uiProcessBar1.Location = new System.Drawing.Point(30, 88);
this.uiProcessBar1.MinimumSize = new System.Drawing.Size(70, 1); this.uiProcessBar1.MinimumSize = new System.Drawing.Size(70, 1);
this.uiProcessBar1.Name = "uiProcessBar1"; this.uiProcessBar1.Name = "uiProcessBar1";
this.uiProcessBar1.Size = new System.Drawing.Size(318, 29); this.uiProcessBar1.Size = new System.Drawing.Size(318, 29);
this.uiProcessBar1.TabIndex = 82; this.uiProcessBar1.TabIndex = 82;
this.uiProcessBar1.Text = "50.0%"; this.uiProcessBar1.Value = 10;
this.uiProcessBar1.Value = 50;
// //
// timer1 // timer1
// //
this.timer1.Tick += new System.EventHandler(this.timer1_Tick); this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
// //
// uiProcessBar3
//
this.uiProcessBar3.Direction = Sunny.UI.UILine.LineDirection.Vertical;
this.uiProcessBar3.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiProcessBar3.Location = new System.Drawing.Point(527, 325);
this.uiProcessBar3.MinimumSize = new System.Drawing.Size(70, 1);
this.uiProcessBar3.Name = "uiProcessBar3";
this.uiProcessBar3.Size = new System.Drawing.Size(203, 169);
this.uiProcessBar3.TabIndex = 103;
this.uiProcessBar3.Value = 50;
//
// uiLine6
//
this.uiLine6.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiLine6.Location = new System.Drawing.Point(527, 287);
this.uiLine6.MinimumSize = new System.Drawing.Size(16, 16);
this.uiLine6.Name = "uiLine6";
this.uiLine6.Size = new System.Drawing.Size(203, 20);
this.uiLine6.TabIndex = 104;
this.uiLine6.Text = "UIProcessBar";
this.uiLine6.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// FProcess // FProcess
// //
this.AllowShowTitle = true; this.AllowShowTitle = true;
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.ClientSize = new System.Drawing.Size(800, 546); this.ClientSize = new System.Drawing.Size(800, 546);
this.Controls.Add(this.uiLine6);
this.Controls.Add(this.uiProcessBar3);
this.Controls.Add(this.uiTrackBar8); this.Controls.Add(this.uiTrackBar8);
this.Controls.Add(this.uiTrackBar7); this.Controls.Add(this.uiTrackBar7);
this.Controls.Add(this.uiTrackBar6); this.Controls.Add(this.uiTrackBar6);
@ -371,5 +394,7 @@ namespace Sunny.UI.Demo
private UILine uiLine3; private UILine uiLine3;
private UIProcessBar uiProcessBar1; private UIProcessBar uiProcessBar1;
private System.Windows.Forms.Timer timer1; private System.Windows.Forms.Timer timer1;
private UIProcessBar uiProcessBar3;
private UILine uiLine6;
} }
} }

View File

@ -572,7 +572,7 @@ namespace Sunny.UI
int pos = FlowPos.Mod(FlowSize + FlowInterval); int pos = FlowPos.Mod(FlowSize + FlowInterval);
for (int i = 0; i < int.MaxValue; i++) for (int i = 0; i < int.MaxValue; i++)
{ {
Rectangle rect = new Rectangle(pos - FlowSize - FlowInterval, 1, FlowSize, Height - 3); Rectangle rect = new Rectangle(pos - FlowSize - FlowInterval, 2, FlowSize, Height - 5);
if (rect.Left > Width) break; if (rect.Left > Width) break;
bool isShow = rect.Left >= 0 & rect.Right <= Width; bool isShow = rect.Left >= 0 & rect.Right <= Width;
@ -596,7 +596,7 @@ namespace Sunny.UI
if (rect.Width >= rect.Height && isShow) if (rect.Width >= rect.Height && isShow)
{ {
g.FillRoundRectangle(color, rect, Radius - 2); g.FillRoundRectangle(color, rect, Radius - 4);
} }
pos += FlowSize; pos += FlowSize;
@ -626,7 +626,7 @@ namespace Sunny.UI
for (int i = 0; i < int.MaxValue; i++) for (int i = 0; i < int.MaxValue; i++)
{ {
Rectangle rect = new Rectangle(1, pos - FlowSize - FlowInterval, Width - 3, FlowSize); Rectangle rect = new Rectangle(2, pos - FlowSize - FlowInterval, Width - 5, FlowSize);
if (rect.Top > Height) break; if (rect.Top > Height) break;
bool isShow = rect.Top >= top & rect.Bottom <= bottom; bool isShow = rect.Top >= top & rect.Bottom <= bottom;
@ -650,7 +650,7 @@ namespace Sunny.UI
if (rect.Height >= rect.Width && isShow) if (rect.Height >= rect.Width && isShow)
{ {
g.FillRoundRectangle(color, rect, Radius - 2); g.FillRoundRectangle(color, rect, Radius - 4);
} }
pos += FlowSize; pos += FlowSize;

View File

@ -23,7 +23,6 @@
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms; using System.Windows.Forms;
namespace Sunny.UI namespace Sunny.UI
@ -49,6 +48,22 @@ namespace Sunny.UI
fillColor = UIColor.LightBlue; fillColor = UIColor.LightBlue;
foreColor = UIColor.Blue; foreColor = UIColor.Blue;
} }
private UILine.LineDirection direction = UILine.LineDirection.Horizontal;
[DefaultValue(UILine.LineDirection.Horizontal)]
[Description("线条方向"), Category("SunnyUI")]
public UILine.LineDirection Direction
{
get => direction;
set
{
if (direction != value)
{
direction = value;
Invalidate();
}
}
}
[DefaultValue(100)] [DefaultValue(100)]
[Description("最大值"), Category("SunnyUI")] [Description("最大值"), Category("SunnyUI")]
@ -73,17 +88,11 @@ namespace Sunny.UI
{ {
posValue = Math.Max(value, 0); posValue = Math.Max(value, 0);
posValue = Math.Min(posValue, maximum); posValue = Math.Min(posValue, maximum);
processWidth = (int)(posValue * Width * 1.0 / Maximum);
processText = (posValue * 100.0 / maximum).ToString("F" + DecimalCount) + "%";
ValueChanged?.Invoke(this, posValue); ValueChanged?.Invoke(this, posValue);
Invalidate(); Invalidate();
} }
} }
private int processWidth;
private string processText = "0.0%";
private bool showValue = true; private bool showValue = true;
[DefaultValue(true)] [DefaultValue(true)]
@ -114,6 +123,19 @@ namespace Sunny.UI
{ {
base.OnPaint(e); base.OnPaint(e);
float processSize;
string processText = "0.0%";
if (Direction == UILine.LineDirection.Horizontal)
processSize = posValue * Width * 1.0f / Maximum;
else
processSize = posValue * Height * 1.0f / Maximum;
if (ShowPercent)
processText = (posValue * 100.0 / maximum).ToString("F" + DecimalCount) + "%";
else
processText = (posValue * 1.0 / maximum).ToString("F" + DecimalCount);
SizeF sf = e.Graphics.MeasureString(processText, Font); SizeF sf = e.Graphics.MeasureString(processText, Font);
bool canShow = Height > sf.Height + 4; bool canShow = Height > sf.Height + 4;
@ -122,10 +144,10 @@ namespace Sunny.UI
e.Graphics.DrawString(processText, Font, foreColor, Size, Padding, TextAlign); e.Graphics.DrawString(processText, Font, foreColor, Size, Padding, TextAlign);
} }
if (image == null || image.Width != Width + 2 || image.Height != Height + 2 || imageRadius != Radius) if (image == null || image.Width != Width || image.Height != Height || imageRadius != Radius)
{ {
image?.Dispose(); image?.Dispose();
image = new Bitmap(Width + 2, Height + 2); image = new Bitmap(Width, Height);
imageRadius = Radius; imageRadius = Radius;
} }
@ -143,26 +165,46 @@ namespace Sunny.UI
g.Dispose(); g.Dispose();
rect = new Rectangle(0, 0, processWidth, image.Height - 1); if (Direction == UILine.LineDirection.Horizontal)
GraphicsPath path = rect.CreateRoundedRectanglePath(0, UICornerRadiusSides.None);
using (Bitmap img = image.Split(path))
{ {
e.Graphics.DrawImage(img, 0, 0); e.Graphics.DrawImage(image,
new RectangleF(0, 0, processSize, image.Height),
new RectangleF(0, 0, processSize, image.Height),
GraphicsUnit.Pixel);
}
else
{
e.Graphics.DrawImage(image,
new RectangleF(0, image.Height - processSize, image.Width, processSize),
new RectangleF(0, image.Height - processSize, image.Width, processSize),
GraphicsUnit.Pixel);
} }
} }
protected override void OnSizeChanged(EventArgs e) protected override void OnSizeChanged(EventArgs e)
{ {
base.OnSizeChanged(e); base.OnSizeChanged(e);
image?.Dispose();
image = null;
processWidth = (int)(posValue * Width * 1.0 / Maximum);
Text = (posValue * 100.0 / maximum).ToString("F" + DecimalCount) + "%";
Invalidate(); Invalidate();
} }
private bool showPercent = true;
[Description("显示文字百分比"), Category("SunnyUI")]
[DefaultValue(true)]
public bool ShowPercent
{
get => showPercent;
set
{
showPercent = value;
Invalidate();
}
}
private int decimalCount = 1; private int decimalCount = 1;
[Description("显示文字小数位数"), Category("SunnyUI")]
[DefaultValue(1)]
public int DecimalCount public int DecimalCount
{ {
get => decimalCount; get => decimalCount;