Defined an own progress bar
This commit is contained in:
parent
32c7865c91
commit
853bde8e6a
48
I18N Commander/UI WinForms/Components/NXProgressBar.Designer.cs
generated
Normal file
48
I18N Commander/UI WinForms/Components/NXProgressBar.Designer.cs
generated
Normal file
@ -0,0 +1,48 @@
|
||||
namespace UI_WinForms.Components
|
||||
{
|
||||
sealed partial class NXProgressBar
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Component Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// NXProgressBar
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(120F, 120F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
|
||||
this.BackColor = System.Drawing.Color.LightSkyBlue;
|
||||
this.Font = new System.Drawing.Font("Segoe UI", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||
this.Margin = new System.Windows.Forms.Padding(0);
|
||||
this.Name = "NXProgressBar";
|
||||
this.Size = new System.Drawing.Size(702, 41);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
73
I18N Commander/UI WinForms/Components/NXProgressBar.cs
Normal file
73
I18N Commander/UI WinForms/Components/NXProgressBar.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using System.ComponentModel;
|
||||
using SolidBrush = System.Drawing.SolidBrush;
|
||||
|
||||
namespace UI_WinForms.Components;
|
||||
|
||||
public sealed partial class NXProgressBar : UserControl
|
||||
{
|
||||
private static readonly SolidBrush BACKGROUND_NOT_FILLED = new(SystemColors.Control);
|
||||
|
||||
private readonly SolidBrush backgroundFilled;
|
||||
private readonly SolidBrush textBrush;
|
||||
|
||||
public NXProgressBar()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
this.backgroundFilled = new SolidBrush(this.BackColor);
|
||||
this.textBrush = new SolidBrush(this.ForeColor);
|
||||
}
|
||||
|
||||
[Category("Settings"), Description("Text to show inside the progress bar.")]
|
||||
public string InformationText { get; set; } = string.Empty;
|
||||
|
||||
[Category("Settings"), Description("The current percentage [0,100] of the progress bar.")]
|
||||
public int PercentInt
|
||||
{
|
||||
get => (int) (this.PercentFloat * 100);
|
||||
set => this.PercentFloat = value / 100f;
|
||||
}
|
||||
|
||||
[Category("Settings"), Description("The current percentage [0,1] of the progress bar.")]
|
||||
public float PercentFloat { get; set; } = 0;
|
||||
|
||||
[Category("Settings"), Description("When true, appends the percentage to the text.")]
|
||||
public bool AppendPercentageToText { get; set; } = true;
|
||||
|
||||
protected override void OnPaintBackground(PaintEventArgs e)
|
||||
{
|
||||
// Do not paint the background.
|
||||
}
|
||||
|
||||
// Draw the progress bar by filling the background of the label with color:
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
base.OnPaint(e);
|
||||
|
||||
var width = (int) MathF.Ceiling((this.Width - this.Margin.Horizontal) * this.PercentFloat);
|
||||
var height = this.Height - this.Margin.Vertical;
|
||||
|
||||
// Erase the background:
|
||||
e.Graphics.FillRectangle(BACKGROUND_NOT_FILLED, this.Margin.Left, this.Margin.Top, this.Width - this.Margin.Horizontal, height);
|
||||
|
||||
// Draw the filled background:
|
||||
e.Graphics.FillRectangle(this.backgroundFilled, this.Margin.Left, this.Margin.Top, width, height);
|
||||
|
||||
// Calculate the text x position by using the margin:
|
||||
var textX = this.Margin.Left + this.Padding.Left;
|
||||
|
||||
// Calculate the text y position by considering the margin:
|
||||
var textY = (int) MathF.Ceiling((this.Height - this.Font.Height) / 2f) + this.Margin.Top + this.Padding.Top;
|
||||
|
||||
// Draw the text horizontally at the beginning, and vertically centered:
|
||||
e.Graphics.DrawString(this.GetTextForRendering(), this.Font, this.textBrush, textX, textY);
|
||||
}
|
||||
|
||||
private string GetTextForRendering()
|
||||
{
|
||||
var text = this.InformationText;
|
||||
if (this.AppendPercentageToText)
|
||||
text += $" ({this.PercentInt}%)";
|
||||
|
||||
return text;
|
||||
}
|
||||
}
|
60
I18N Commander/UI WinForms/Components/NXProgressBar.resx
Normal file
60
I18N Commander/UI WinForms/Components/NXProgressBar.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<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>
|
Loading…
Reference in New Issue
Block a user