Skip to content

Commit

Permalink
Merge pull request #8 from Lokyyn/feature/progressBarText
Browse files Browse the repository at this point in the history
Feature/progress bar text
  • Loading branch information
Lokyyn authored Apr 27, 2024
2 parents ac50424 + 6be0362 commit 3f0572f
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 3 deletions.
51 changes: 51 additions & 0 deletions source/Lucid.Sample/Pages/MainPage.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions source/Lucid.Sample/Pages/MainPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
34 changes: 31 additions & 3 deletions source/Lucid/Controls/LucidProgressBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand All @@ -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);

Expand Down Expand Up @@ -163,7 +191,7 @@ public int Value
updateRect.Height = this.Height;

// Invalidate the intersection region only.
this.Invalidate(updateRect);
this.Invalidate();
}
}

Expand Down

0 comments on commit 3f0572f

Please sign in to comment.