Commit 33a4024f HZH

圆形进度条

1 个父辈 b9e4603b
namespace HZH_Controls.Controls
{
partial class UCProcessEllipse
{
/// <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();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
}
#endregion
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace HZH_Controls.Controls
{
public partial class UCProcessEllipse : UserControl
{
[Description("值改变事件"), Category("自定义")]
public event EventHandler ValueChanged;
private Color m_backEllipseColor = Color.FromArgb(22, 160, 133);
/// <summary>
/// 圆背景色
/// </summary>
[Description("圆背景色"), Category("自定义")]
public Color BackEllipseColor
{
get { return m_backEllipseColor; }
set
{
m_backEllipseColor = value;
Refresh();
}
}
private Color m_coreEllipseColor = Color.FromArgb(180, 180, 180);
/// <summary>
/// 内圆颜色,ShowType=Ring 有效
/// </summary>
[Description("内圆颜色,ShowType=Ring 有效"), Category("自定义")]
public Color CoreEllipseColor
{
get { return m_coreEllipseColor; }
set
{
m_coreEllipseColor = value;
Refresh();
}
}
private Color m_valueColor = Color.FromArgb(255, 77, 59);
[Description("值圆颜色"), Category("自定义")]
public Color ValueColor
{
get { return m_valueColor; }
set
{
m_valueColor = value;
Refresh();
}
}
private bool m_isShowCoreEllipseBorder = true;
/// <summary>
/// 内圆是否显示边框,ShowType=Ring 有效
/// </summary>
[Description("内圆是否显示边框,ShowType=Ring 有效"), Category("自定义")]
public bool IsShowCoreEllipseBorder
{
get { return m_isShowCoreEllipseBorder; }
set
{
m_isShowCoreEllipseBorder = value;
Refresh();
}
}
private ValueType m_valueType = ValueType.Percent;
/// <summary>
/// 值文字类型
/// </summary>
[Description("值文字类型"), Category("自定义")]
public ValueType ValueType
{
get { return m_valueType; }
set
{
m_valueType = value;
Refresh();
}
}
private int m_valueWidth = 30;
/// <summary>
/// 外圆值宽度
/// </summary>
[Description("外圆值宽度,ShowType=Ring 有效"), Category("自定义")]
public int ValueWidth
{
get { return m_valueWidth; }
set
{
if (value <= 0 || value > Math.Min(this.Width, this.Height))
return;
m_valueWidth = value;
Refresh();
}
}
private int m_valueMargin = 5;
/// <summary>
/// 外圆值间距
/// </summary>
[Description("外圆值间距"), Category("自定义")]
public int ValueMargin
{
get { return m_valueMargin; }
set
{
if (value < 0 || m_valueMargin >= m_valueWidth)
return;
m_valueMargin = value;
Refresh();
}
}
private int m_maxValue = 100;
/// <summary>
/// 最大值
/// </summary>
[Description("最大值"), Category("自定义")]
public int MaxValue
{
get { return m_maxValue; }
set
{
if (value > m_value || value <= 0)
return;
m_maxValue = value;
Refresh();
}
}
private int m_value = 0;
/// <summary>
/// 当前值
/// </summary>
[Description("当前值"), Category("自定义")]
public int Value
{
get { return m_value; }
set
{
if (m_maxValue < value || value <= 0)
return;
m_value = value;
if (ValueChanged != null)
{
ValueChanged(this, null);
}
Refresh();
}
}
private Font m_font = new Font("Arial Unicode MS", 20);
[Description("文字字体"), Category("自定义")]
public override Font Font
{
get
{
return m_font;
}
set
{
m_font = value;
Refresh();
}
}
Color m_foreColor = Color.White;
[Description("文字颜色"), Category("自定义")]
public override Color ForeColor
{
get
{
return m_foreColor;
}
set
{
m_foreColor = value;
Refresh();
}
}
private ShowType m_showType = ShowType.Ring;
[Description("显示类型"), Category("自定义")]
public ShowType ShowType
{
get { return m_showType; }
set
{
m_showType = value;
Refresh();
}
}
public UCProcessEllipse()
{
InitializeComponent();
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(ControlStyles.Selectable, true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
this.SetStyle(ControlStyles.UserPaint, true);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
var g = e.Graphics;
g.SmoothingMode = SmoothingMode.AntiAlias; //使绘图质量最高,即消除锯齿
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.CompositingQuality = CompositingQuality.HighQuality;
int intWidth = Math.Min(this.Size.Width, this.Size.Height);
//底圆
g.FillEllipse(new SolidBrush(m_backEllipseColor), new Rectangle(new Point(0, 0), new Size(intWidth, intWidth)));
if (m_showType == HZH_Controls.Controls.ShowType.Ring)
{
//中心圆
int intCore = intWidth - m_valueWidth * 2;
g.FillEllipse(new SolidBrush(m_coreEllipseColor), new Rectangle(new Point(m_valueWidth, m_valueWidth), new Size(intCore, intCore)));
//中心圆边框
if (m_isShowCoreEllipseBorder)
{
g.DrawEllipse(new Pen(m_valueColor, 2), new Rectangle(new Point(m_valueWidth + 1, m_valueWidth + 1), new Size(intCore - 1, intCore - 1)));
}
if (m_value > 0 && m_maxValue > 0)
{
float fltPercent = (float)m_value / (float)m_maxValue;
if (fltPercent > 1)
{
fltPercent = 1;
}
g.DrawArc(new Pen(m_valueColor, m_valueWidth - m_valueMargin * 2), new RectangleF(new Point(m_valueWidth / 2 + m_valueMargin / 4, m_valueWidth / 2 + m_valueMargin / 4), new SizeF(intWidth - m_valueWidth - m_valueMargin / 2 + (m_valueMargin == 0 ? 0 : 1), intWidth - m_valueWidth - m_valueMargin / 2 + (m_valueMargin == 0 ? 0 : 1))), -90, fltPercent * 360);
string strValueText = m_valueType == HZH_Controls.Controls.ValueType.Percent ? fltPercent.ToString("0%") : m_value.ToString();
System.Drawing.SizeF _txtSize = g.MeasureString(strValueText, this.Font);
g.DrawString(strValueText, this.Font, new SolidBrush(this.ForeColor), new PointF((intWidth - _txtSize.Width) / 2 + 1, (intWidth - _txtSize.Height) / 2 + 1));
}
}
else
{
if (m_value > 0 && m_maxValue > 0)
{
float fltPercent = (float)m_value / (float)m_maxValue;
if (fltPercent > 1)
{
fltPercent = 1;
}
g.FillPie(new SolidBrush(m_valueColor), new Rectangle(m_valueMargin, m_valueMargin, intWidth - m_valueMargin * 2, intWidth - m_valueMargin * 2), -90, fltPercent * 360);
string strValueText = m_valueType == HZH_Controls.Controls.ValueType.Percent ? fltPercent.ToString("0%") : m_value.ToString();
System.Drawing.SizeF _txtSize = g.MeasureString(strValueText, this.Font);
g.DrawString(strValueText, this.Font, new SolidBrush(this.ForeColor), new PointF((intWidth - _txtSize.Width) / 2 + 1, (intWidth - _txtSize.Height) / 2 + 1));
}
}
}
}
public enum ValueType
{
/// <summary>
/// 百分比
/// </summary>
Percent,
/// <summary>
/// 数值
/// </summary>
Absolute
}
public enum ShowType
{
/// <summary>
/// 圆环
/// </summary>
Ring,
/// <summary>
/// 扇形
/// </summary>
Sector
}
}
namespace HZH_Controls.Controls namespace HZH_Controls.Controls
{ {
partial class ProcessExt partial class UCProcessExt
{ {
/// <summary> /// <summary>
/// 必需的设计器变量。 /// 必需的设计器变量。
......
...@@ -14,7 +14,7 @@ using System.Windows.Forms; ...@@ -14,7 +14,7 @@ using System.Windows.Forms;
namespace HZH_Controls.Controls namespace HZH_Controls.Controls
{ {
public partial class ProcessExt : UCControlBase public partial class UCProcessExt : UCControlBase
{ {
private int _value = 0; private int _value = 0;
...@@ -50,7 +50,7 @@ namespace HZH_Controls.Controls ...@@ -50,7 +50,7 @@ namespace HZH_Controls.Controls
this.panel1.Width = (int)(this.Width * dbl); this.panel1.Width = (int)(this.Width * dbl);
} }
public ProcessExt() public UCProcessExt()
{ {
InitializeComponent(); InitializeComponent();
} }
......
...@@ -104,6 +104,12 @@ ...@@ -104,6 +104,12 @@
<Compile Include="Controls\Panel\UCPanelTitle.Designer.cs"> <Compile Include="Controls\Panel\UCPanelTitle.Designer.cs">
<DependentUpon>UCPanelTitle.cs</DependentUpon> <DependentUpon>UCPanelTitle.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Controls\Process\UCProcessEllipse.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Controls\Process\UCProcessEllipse.Designer.cs">
<DependentUpon>UCProcessEllipse.cs</DependentUpon>
</Compile>
<Compile Include="Controls\Step\UCStep.cs"> <Compile Include="Controls\Step\UCStep.cs">
<SubType>UserControl</SubType> <SubType>UserControl</SubType>
</Compile> </Compile>
...@@ -211,11 +217,11 @@ ...@@ -211,11 +217,11 @@
<Compile Include="Controls\List\UCPagerControlBase.cs"> <Compile Include="Controls\List\UCPagerControlBase.cs">
<SubType>UserControl</SubType> <SubType>UserControl</SubType>
</Compile> </Compile>
<Compile Include="Controls\Process\ProcessExt.cs"> <Compile Include="Controls\Process\UCProcessExt.cs">
<SubType>UserControl</SubType> <SubType>UserControl</SubType>
</Compile> </Compile>
<Compile Include="Controls\Process\ProcessExt.Designer.cs"> <Compile Include="Controls\Process\UCProcessExt.Designer.cs">
<DependentUpon>ProcessExt.cs</DependentUpon> <DependentUpon>UCProcessExt.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Controls\RadioButton\UCRadioButton.cs"> <Compile Include="Controls\RadioButton\UCRadioButton.cs">
<SubType>UserControl</SubType> <SubType>UserControl</SubType>
...@@ -417,8 +423,8 @@ ...@@ -417,8 +423,8 @@
<EmbeddedResource Include="Controls\Panel\UCPanelTitle.resx"> <EmbeddedResource Include="Controls\Panel\UCPanelTitle.resx">
<DependentUpon>UCPanelTitle.cs</DependentUpon> <DependentUpon>UCPanelTitle.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="Controls\Process\ProcessExt.resx"> <EmbeddedResource Include="Controls\Process\UCProcessExt.resx">
<DependentUpon>ProcessExt.cs</DependentUpon> <DependentUpon>UCProcessExt.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="Controls\RadioButton\UCRadioButton.resx"> <EmbeddedResource Include="Controls\RadioButton\UCRadioButton.resx">
<DependentUpon>UCRadioButton.cs</DependentUpon> <DependentUpon>UCRadioButton.cs</DependentUpon>
......
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
this.ucBtnsGroup1 = new HZH_Controls.Controls.UCBtnsGroup(); this.ucBtnsGroup1 = new HZH_Controls.Controls.UCBtnsGroup();
this.groupBox13 = new System.Windows.Forms.GroupBox(); this.groupBox13 = new System.Windows.Forms.GroupBox();
this.ucBtnsGroup2 = new HZH_Controls.Controls.UCBtnsGroup(); this.ucBtnsGroup2 = new HZH_Controls.Controls.UCBtnsGroup();
this.processExt1 = new HZH_Controls.Controls.ProcessExt(); this.processExt1 = new HZH_Controls.Controls.UCProcessExt();
this.ucSplitLine_H1 = new HZH_Controls.Controls.UCSplitLine_H(); this.ucSplitLine_H1 = new HZH_Controls.Controls.UCSplitLine_H();
this.ucSplitLine_V1 = new HZH_Controls.Controls.UCSplitLine_V(); this.ucSplitLine_V1 = new HZH_Controls.Controls.UCSplitLine_V();
this.groupBox1.SuspendLayout(); this.groupBox1.SuspendLayout();
...@@ -1102,7 +1102,7 @@ ...@@ -1102,7 +1102,7 @@
private HZH_Controls.Controls.UCBtnsGroup ucBtnsGroup1; private HZH_Controls.Controls.UCBtnsGroup ucBtnsGroup1;
private System.Windows.Forms.GroupBox groupBox13; private System.Windows.Forms.GroupBox groupBox13;
private HZH_Controls.Controls.UCBtnsGroup ucBtnsGroup2; private HZH_Controls.Controls.UCBtnsGroup ucBtnsGroup2;
private HZH_Controls.Controls.ProcessExt processExt1; private HZH_Controls.Controls.UCProcessExt processExt1;
private HZH_Controls.Controls.UCSplitLine_H ucSplitLine_H1; private HZH_Controls.Controls.UCSplitLine_H ucSplitLine_H1;
private HZH_Controls.Controls.UCSplitLine_V ucSplitLine_V1; private HZH_Controls.Controls.UCSplitLine_V ucSplitLine_V1;
} }
......
...@@ -28,10 +28,35 @@ ...@@ -28,10 +28,35 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.components = new System.ComponentModel.Container();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.ucProcessEllipse1 = new HZH_Controls.Controls.UCProcessEllipse();
this.ucPanelTitle1 = new HZH_Controls.Controls.UCPanelTitle(); this.ucPanelTitle1 = new HZH_Controls.Controls.UCPanelTitle();
this.ucStep1 = new HZH_Controls.Controls.UCStep(); this.ucStep1 = new HZH_Controls.Controls.UCStep();
this.SuspendLayout(); this.SuspendLayout();
// //
// timer1
//
this.timer1.Enabled = true;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// ucProcessEllipse1
//
this.ucProcessEllipse1.BackEllipseColor = System.Drawing.Color.FromArgb(((int)(((byte)(22)))), ((int)(((byte)(160)))), ((int)(((byte)(133)))));
this.ucProcessEllipse1.CoreEllipseColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(180)))), ((int)(((byte)(180)))));
this.ucProcessEllipse1.IsShowCoreEllipseBorder = true;
this.ucProcessEllipse1.Location = new System.Drawing.Point(78, 117);
this.ucProcessEllipse1.MaxValue = 100;
this.ucProcessEllipse1.Name = "ucProcessEllipse1";
this.ucProcessEllipse1.ShowType = HZH_Controls.Controls.ShowType.Sector;
this.ucProcessEllipse1.Size = new System.Drawing.Size(150, 150);
this.ucProcessEllipse1.TabIndex = 2;
this.ucProcessEllipse1.Value = 45;
this.ucProcessEllipse1.ValueColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
this.ucProcessEllipse1.ValueMargin = 0;
this.ucProcessEllipse1.ValueType = HZH_Controls.Controls.ValueType.Percent;
this.ucProcessEllipse1.ValueWidth = 30;
//
// ucPanelTitle1 // ucPanelTitle1
// //
this.ucPanelTitle1.BackColor = System.Drawing.Color.Transparent; this.ucPanelTitle1.BackColor = System.Drawing.Color.Transparent;
...@@ -74,6 +99,7 @@ ...@@ -74,6 +99,7 @@
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.BackColor = System.Drawing.Color.White; this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(825, 594); this.ClientSize = new System.Drawing.Size(825, 594);
this.Controls.Add(this.ucProcessEllipse1);
this.Controls.Add(this.ucPanelTitle1); this.Controls.Add(this.ucPanelTitle1);
this.Controls.Add(this.ucStep1); this.Controls.Add(this.ucStep1);
this.Name = "Form2"; this.Name = "Form2";
...@@ -86,5 +112,7 @@ ...@@ -86,5 +112,7 @@
private HZH_Controls.Controls.UCStep ucStep1; private HZH_Controls.Controls.UCStep ucStep1;
private HZH_Controls.Controls.UCPanelTitle ucPanelTitle1; private HZH_Controls.Controls.UCPanelTitle ucPanelTitle1;
private HZH_Controls.Controls.UCProcessEllipse ucProcessEllipse1;
private System.Windows.Forms.Timer timer1;
} }
} }
\ No newline at end of file \ No newline at end of file
...@@ -20,5 +20,12 @@ namespace Test ...@@ -20,5 +20,12 @@ namespace Test
{ {
this.ucStep1.StepIndex = 3; this.ucStep1.StepIndex = 3;
} }
private void timer1_Tick(object sender, EventArgs e)
{
this.ucProcessEllipse1.Value++;
if (this.ucProcessEllipse1.Value == 100)
timer1.Enabled = false;
}
} }
} }
...@@ -117,4 +117,7 @@ ...@@ -117,4 +117,7 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root> </root>
\ No newline at end of file \ No newline at end of file
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!