diff --git a/source/Lucid.Sample/Pages/MainPage.Designer.cs b/source/Lucid.Sample/Pages/MainPage.Designer.cs index 8a01eed..a0dc862 100644 --- a/source/Lucid.Sample/Pages/MainPage.Designer.cs +++ b/source/Lucid.Sample/Pages/MainPage.Designer.cs @@ -34,6 +34,9 @@ private void InitializeComponent() btRemoveChip = new Controls.LucidButton(); lucidScrollableControl1 = new Controls.LucidScrollableControl(); lucidButton1 = new Controls.LucidButton(); + lucidProgressBar = new Controls.LucidProgressBar(); + btnProgressBarAdd = new Controls.LucidButton(); + btnProgressBarRemove = new Controls.LucidButton(); btnShowMessageBox = new Controls.LucidButton(); lucidFileDrop1 = new Controls.LucidFileDrop(); lucidScrollableControl1.SuspendLayout(); @@ -102,6 +105,45 @@ private void InitializeComponent() lucidButton1.TabIndex = 9; lucidButton1.Text = "lucidButton1"; // + // lucidProgressBar + // + lucidProgressBar.AllowProgressBarColorOverride = false; + lucidProgressBar.Location = new Point(340, 107); + lucidProgressBar.Maximum = 100; + lucidProgressBar.Minimum = 0; + lucidProgressBar.Name = "lucidProgressBar"; + lucidProgressBar.ProgressBarColor = Color.FromArgb(104, 151, 187); + lucidProgressBar.ShowPercentage = true; + lucidProgressBar.Size = new Size(283, 20); + lucidProgressBar.TabIndex = 9; + lucidProgressBar.Value = 0; + // + // btnProgressBarAdd + // + btnProgressBarAdd.BackColor = Color.Transparent; + btnProgressBarAdd.ButtonStyle = Lucid.Controls.LucidButtonStyle.Rounded; + btnProgressBarAdd.Location = new Point(340, 78); + btnProgressBarAdd.Name = "btnProgressBarAdd"; + btnProgressBarAdd.Padding = new Padding(5); + btnProgressBarAdd.RoundedCornerRadius = 16; + btnProgressBarAdd.Size = new Size(32, 23); + btnProgressBarAdd.TabIndex = 10; + btnProgressBarAdd.Text = "+"; + btnProgressBarAdd.Click += btnProgressBarAdd_Click; + // + // btnProgressBarRemove + // + btnProgressBarRemove.BackColor = Color.Transparent; + btnProgressBarRemove.ButtonStyle = Lucid.Controls.LucidButtonStyle.Rounded; + btnProgressBarRemove.Location = new Point(378, 78); + btnProgressBarRemove.Name = "btnProgressBarRemove"; + btnProgressBarRemove.Padding = new Padding(5); + btnProgressBarRemove.RoundedCornerRadius = 16; + btnProgressBarRemove.Size = new Size(32, 23); + btnProgressBarRemove.TabIndex = 11; + btnProgressBarRemove.Text = "-"; + btnProgressBarRemove.Click += btnProgressBarRemove_Click; + // // btnShowMessageBox // btnShowMessageBox.BackColor = Color.Transparent; @@ -131,6 +173,9 @@ private void InitializeComponent() // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; + Controls.Add(btnProgressBarRemove); + Controls.Add(btnProgressBarAdd); + Controls.Add(lucidProgressBar); Controls.Add(lucidFileDrop1); Controls.Add(btnShowMessageBox); Controls.Add(lucidScrollableControl1); @@ -146,6 +191,9 @@ private void InitializeComponent() Controls.SetChildIndex(btAddChip, 0); Controls.SetChildIndex(btRemoveChip, 0); Controls.SetChildIndex(lucidScrollableControl1, 0); + Controls.SetChildIndex(lucidProgressBar, 0); + Controls.SetChildIndex(btnProgressBarAdd, 0); + Controls.SetChildIndex(btnProgressBarRemove, 0); Controls.SetChildIndex(btnShowMessageBox, 0); Controls.SetChildIndex(lucidFileDrop1, 0); lucidScrollableControl1.ResumeLayout(false); @@ -159,6 +207,9 @@ private void InitializeComponent() private Controls.LucidButton btRemoveChip; private Controls.LucidScrollableControl lucidScrollableControl1; private Controls.LucidButton lucidButton1; + private Controls.LucidProgressBar lucidProgressBar; + private Controls.LucidButton btnProgressBarAdd; + private Controls.LucidButton btnProgressBarRemove; private Controls.LucidButton btnShowMessageBox; private Controls.LucidFileDrop lucidFileDrop1; } diff --git a/source/Lucid.Sample/Pages/MainPage.cs b/source/Lucid.Sample/Pages/MainPage.cs index f8b53e7..370eced 100644 --- a/source/Lucid.Sample/Pages/MainPage.cs +++ b/source/Lucid.Sample/Pages/MainPage.cs @@ -74,6 +74,20 @@ private void lucidChipControl1_OnChipDeleted(Controls.Chip deletedChip) } + private void btnProgressBarAdd_Click(object sender, EventArgs e) + { + Random rnd = new Random(); + + lucidProgressBar.Value += rnd.Next(1, 15); + } + + private void btnProgressBarRemove_Click(object sender, EventArgs e) + { + Random rnd = new Random(); + + lucidProgressBar.Value -= rnd.Next(1, 15); + } + private void btnShowMessageBox_Click(object sender, EventArgs e) { Lucid.Forms.LucidMessageBox.ShowInformation("This is just an test message with an long text that has no meaning", "Information"); diff --git a/source/Lucid/Controls/LucidProgressBar.cs b/source/Lucid/Controls/LucidProgressBar.cs index aba3463..71dd32f 100644 --- a/source/Lucid/Controls/LucidProgressBar.cs +++ b/source/Lucid/Controls/LucidProgressBar.cs @@ -9,6 +9,23 @@ public partial class LucidProgressBar : UserControl int val = 0; // Current progress Color BarColor = ThemeProvider.Theme.Colors.ControlHighlight; // Color of progress meter + public bool ShowPercentage { get; set; } + + public Color PercentageTextColor { get; set; } = Color.Black; + + public Font PercentageFont { get; set; } = new Font(new FontFamily("Arial"), 7); + + + private float _CurrentPercentage + { + get + { + float percent = (float)(val - min) / (float)(max - min); + + return percent; + } + } + public LucidProgressBar() { InitializeComponent(); @@ -24,7 +41,6 @@ protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; SolidBrush brush = new SolidBrush(BarColor); - float percent = (float)(val - min) / (float)(max - min); Rectangle rect = this.ClientRectangle; // Draw Theming Colors @@ -33,11 +49,23 @@ protected override void OnPaint(PaintEventArgs e) g.FillRectangle(brushTheming, rect); // Calculate area for drawing the progress. - rect.Width = (int)((float)rect.Width * percent); + rect.Width = (int)((float)rect.Width * _CurrentPercentage); // Draw the progress meter. g.FillRectangle(brush, rect); + if (ShowPercentage) + { + g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; + + var percentageText = $"{Math.Round(_CurrentPercentage * 100)}%"; + var measuredString = g.MeasureString(percentageText, PercentageFont); + + var point = new Point((ClientRectangle.Width / 2) - (int)measuredString.Width / 2, (ClientRectangle.Height / 2) - (int)measuredString.Height / 2); + + g.DrawString(percentageText, PercentageFont, new SolidBrush(PercentageTextColor), point); + } + // Draw a three-dimensional border around the control. Draw3DBorder(g); @@ -163,7 +191,7 @@ public int Value updateRect.Height = this.Height; // Invalidate the intersection region only. - this.Invalidate(updateRect); + this.Invalidate(); } }