Commit ef262ac9 HZH

添加进度条扩展

1 个父辈 c4c680ed
......@@ -10,6 +10,7 @@ using System.Drawing.Drawing2D;
namespace HZH_Controls.Controls
{
[DefaultEvent("ValueChanged")]
public class UCProcessLine : Control
{
[Description("值变更事件"), Category("自定义")]
......@@ -145,17 +146,16 @@ namespace HZH_Controls.Controls
protected override void OnPaint(PaintEventArgs e)
{
Console.WriteLine(DateTime.Now);
base.OnPaint(e);
Graphics g = e.Graphics;
g.SetGDIHigh();
Brush sb = new SolidBrush(m_valueBGColor);
g.FillRectangle(sb, new Rectangle(base.ClientRectangle.X, base.ClientRectangle.Y, base.ClientRectangle.Width - 3, base.ClientRectangle.Height - 2));
GraphicsPath path1 = ControlHelper.CreateRoundedRectanglePath(new Rectangle(base.ClientRectangle.X, base.ClientRectangle.Y + 1, base.ClientRectangle.Width - 3, base.ClientRectangle.Height - 4), 3);
GraphicsPath path1 = ControlHelper.CreateRoundedRectanglePath(new Rectangle(base.ClientRectangle.X, base.ClientRectangle.Y + 1, base.ClientRectangle.Width - 3, base.ClientRectangle.Height - 4), 2);
g.DrawPath(new Pen(m_borderColor, 1), path1);
LinearGradientBrush lgb = new LinearGradientBrush(new Point(0, 0), new Point(0, base.ClientRectangle.Height - 3), m_valueColor, Color.FromArgb(200, m_valueColor.R, m_valueColor.G, m_valueColor.B));
g.FillPath(lgb, ControlHelper.CreateRoundedRectanglePath(new Rectangle(0, (base.ClientRectangle.Height - (base.ClientRectangle.Height - 3)) / 2, (base.ClientRectangle.Width - 3) * Value / m_maxValue, base.ClientRectangle.Height - 4), 3));
g.FillPath(lgb, ControlHelper.CreateRoundedRectanglePath(new Rectangle(0, (base.ClientRectangle.Height - (base.ClientRectangle.Height - 3)) / 2, (base.ClientRectangle.Width - 3) * Value / m_maxValue, base.ClientRectangle.Height - 4), 2));
string strValue = string.Empty;
if (m_valueTextType == HZH_Controls.Controls.ValueTextType.Percent)
strValue = ((float)Value / (float)m_maxValue).ToString("0%");
......
namespace HZH_Controls.Controls
{
partial class UCProcessLineExt
{
/// <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()
{
this.ucProcessLine1 = new HZH_Controls.Controls.UCProcessLine();
this.SuspendLayout();
//
// ucProcessLine1
//
this.ucProcessLine1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.ucProcessLine1.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
this.ucProcessLine1.Font = new System.Drawing.Font("Arial Unicode MS", 10F);
this.ucProcessLine1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
this.ucProcessLine1.Location = new System.Drawing.Point(18, 33);
this.ucProcessLine1.MaxValue = 100;
this.ucProcessLine1.Name = "ucProcessLine1";
this.ucProcessLine1.Size = new System.Drawing.Size(399, 16);
this.ucProcessLine1.TabIndex = 0;
this.ucProcessLine1.Text = "ucProcessLine1";
this.ucProcessLine1.Value = 0;
this.ucProcessLine1.ValueBGColor = System.Drawing.Color.White;
this.ucProcessLine1.ValueColor = System.Drawing.Color.FromArgb(((int)(((byte)(73)))), ((int)(((byte)(119)))), ((int)(((byte)(232)))));
this.ucProcessLine1.ValueTextType = HZH_Controls.Controls.ValueTextType.None;
//
// UCProcessLineExt
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.BackColor = System.Drawing.Color.Transparent;
this.Controls.Add(this.ucProcessLine1);
this.Name = "UCProcessLineExt";
this.Size = new System.Drawing.Size(434, 50);
this.ResumeLayout(false);
}
#endregion
private UCProcessLine ucProcessLine1;
}
}
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 UCProcessLineExt : UserControl
{
[Description("值变更事件"), Category("自定义")]
public event EventHandler ValueChanged;
[Description("当前属性"), Category("自定义")]
public int Value
{
set
{
ucProcessLine1.Value = value;
Refresh();
}
get
{
return ucProcessLine1.Value;
}
}
[Description("最大值"), Category("自定义")]
public int MaxValue
{
get { return ucProcessLine1.MaxValue; }
set
{
ucProcessLine1.MaxValue = value;
Refresh();
}
}
[Description("值进度条颜色"), Category("自定义")]
public Color ValueColor
{
get { return ucProcessLine1.ValueColor; }
set
{
ucProcessLine1.ValueColor = value;
Refresh();
}
}
[Description("值背景色"), Category("自定义")]
public Color ValueBGColor
{
get { return ucProcessLine1.ValueBGColor; }
set
{
ucProcessLine1.ValueBGColor = value;
Refresh();
}
}
[Description("边框颜色"), Category("自定义")]
public Color BorderColor
{
get { return ucProcessLine1.BorderColor; }
set
{
ucProcessLine1.BorderColor = value;
Refresh();
}
}
[Description("值字体"), Category("自定义")]
public override Font Font
{
get
{
return ucProcessLine1.Font;
}
set
{
ucProcessLine1.Font = value;
Refresh();
}
}
[Description("值块颜色"), Category("自定义")]
public override System.Drawing.Color ForeColor
{
get
{
return base.ForeColor;
}
set
{
base.ForeColor = value;
Refresh();
}
}
public UCProcessLineExt()
{
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);
ucProcessLine1.ValueChanged += ucProcessLine1_ValueChanged;
}
void ucProcessLine1_ValueChanged(object sender, EventArgs e)
{
if (ValueChanged != null)
{
ValueChanged(this, e);
}
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.SetGDIHigh();
float fltIndex = (float)this.ucProcessLine1.Value / (float)this.ucProcessLine1.MaxValue;
int x = (int)(fltIndex * this.ucProcessLine1.Width + this.ucProcessLine1.Location.X - 15) - 2;
GraphicsPath path = new GraphicsPath();
Rectangle rect = new Rectangle(x, 1, 30, 20);
int cornerRadius = 2;
path.AddArc(rect.X, rect.Y, cornerRadius * 2, cornerRadius * 2, 180, 90);
path.AddLine(rect.X + cornerRadius, rect.Y, rect.Right - cornerRadius * 2, rect.Y);
path.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y, cornerRadius * 2, cornerRadius * 2, 270, 90);
path.AddLine(rect.Right, rect.Y + cornerRadius * 2, rect.Right, rect.Y + rect.Height - cornerRadius * 2);
path.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y + rect.Height - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 0, 90);
path.AddLine(rect.Right - cornerRadius * 2, rect.Bottom, rect.Right - cornerRadius * 2 - 5, rect.Bottom);//下
path.AddLine(rect.Right - cornerRadius * 2 - 5, 21, x + 15, ucProcessLine1.Location.Y);
path.AddLine(x + 15, ucProcessLine1.Location.Y, rect.X + cornerRadius * 2 + 5, 21);
path.AddLine(rect.X + cornerRadius * 2 + 5, 20, rect.X + cornerRadius * 2, rect.Bottom);//下
path.AddArc(rect.X, rect.Bottom - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 90, 90);
path.AddLine(rect.X, rect.Bottom - cornerRadius * 2, rect.X, rect.Y + cornerRadius * 2);//上
path.CloseFigure();
e.Graphics.FillPath(new SolidBrush(ForeColor), path);
string strValue = ((float)Value / (float)MaxValue).ToString("0%");
System.Drawing.SizeF sizeF = e.Graphics.MeasureString(strValue, Font);
e.Graphics.DrawString(strValue, Font, new SolidBrush(Color.White), new PointF(x + (30 - sizeF.Width) / 2+1, (20 - sizeF.Height) / 2 + 1));
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file
......@@ -120,6 +120,12 @@
<Compile Include="Controls\Process\UCProcessLine.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\Process\UCProcessLineExt.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Controls\Process\UCProcessLineExt.Designer.cs">
<DependentUpon>UCProcessLineExt.cs</DependentUpon>
</Compile>
<Compile Include="Controls\Step\UCStep.cs">
<SubType>UserControl</SubType>
</Compile>
......@@ -449,6 +455,9 @@
<EmbeddedResource Include="Controls\Process\UCProcessExt.resx">
<DependentUpon>UCProcessExt.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Controls\Process\UCProcessLineExt.resx">
<DependentUpon>UCProcessLineExt.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Controls\RadioButton\UCRadioButton.resx">
<DependentUpon>UCRadioButton.cs</DependentUpon>
</EmbeddedResource>
......
......@@ -28,9 +28,9 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form2));
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.timer1 = new System.Windows.Forms.Timer();
this.ucProcessLineExt1 = new HZH_Controls.Controls.UCProcessLineExt();
this.ucProcessLine1 = new HZH_Controls.Controls.UCProcessLine();
this.ucSwitch10 = new HZH_Controls.Controls.UCSwitch();
this.ucSwitch9 = new HZH_Controls.Controls.UCSwitch();
......@@ -55,9 +55,24 @@
this.timer1.Enabled = true;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// ucProcessLineExt1
//
this.ucProcessLineExt1.BackColor = System.Drawing.Color.Transparent;
this.ucProcessLineExt1.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
this.ucProcessLineExt1.Location = new System.Drawing.Point(406, 287);
this.ucProcessLineExt1.MaxValue = 100;
this.ucProcessLineExt1.Name = "ucProcessLineExt1";
this.ucProcessLineExt1.Size = new System.Drawing.Size(269, 50);
this.ucProcessLineExt1.TabIndex = 6;
this.ucProcessLineExt1.Value = 20;
this.ucProcessLineExt1.ValueBGColor = System.Drawing.Color.White;
this.ucProcessLineExt1.ValueColor = System.Drawing.Color.FromArgb(((int)(((byte)(73)))), ((int)(((byte)(119)))), ((int)(((byte)(232)))));
//
// ucProcessLine1
//
this.ucProcessLine1.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
this.ucProcessLine1.Font = new System.Drawing.Font("Arial Unicode MS", 10F);
this.ucProcessLine1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
this.ucProcessLine1.Location = new System.Drawing.Point(406, 224);
this.ucProcessLine1.MaxValue = 150;
this.ucProcessLine1.Name = "ucProcessLine1";
......@@ -67,6 +82,7 @@
this.ucProcessLine1.Value = 150;
this.ucProcessLine1.ValueBGColor = System.Drawing.Color.White;
this.ucProcessLine1.ValueColor = System.Drawing.Color.FromArgb(((int)(((byte)(73)))), ((int)(((byte)(119)))), ((int)(((byte)(232)))));
this.ucProcessLine1.ValueTextType = HZH_Controls.Controls.ValueTextType.Percent;
//
// ucSwitch10
//
......@@ -324,6 +340,7 @@
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(825, 594);
this.Controls.Add(this.ucProcessLineExt1);
this.Controls.Add(this.ucProcessLine1);
this.Controls.Add(this.ucSwitch10);
this.Controls.Add(this.ucSwitch9);
......@@ -368,5 +385,6 @@
private HZH_Controls.Controls.UCProcessEllipse ucProcessEllipse2;
private HZH_Controls.Controls.UCStep ucStep2;
private HZH_Controls.Controls.UCProcessLine ucProcessLine1;
private HZH_Controls.Controls.UCProcessLineExt ucProcessLineExt1;
}
}
\ No newline at end of file
......@@ -26,12 +26,16 @@ namespace Test
this.ucProcessEllipse1.Value++;
this.ucProcessEllipse2.Value++;
this.ucProcessLine1.Value++;
ucProcessLineExt1.Value++;
if (this.ucProcessEllipse1.Value == 100)
this.ucProcessEllipse1.Value = 0;
if (this.ucProcessEllipse2.Value == 100)
this.ucProcessEllipse2.Value = 0;
if (this.ucProcessLine1.Value >= this.ucProcessLine1.MaxValue)
this.ucProcessLine1.Value = 0;
if (this.ucProcessLineExt1.Value >= this.ucProcessLineExt1.MaxValue)
this.ucProcessLineExt1.Value = 0;
}
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!