-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Lothindir/Francis
Francis
- Loading branch information
Showing
9 changed files
with
389 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
|
||
namespace ThemePacker | ||
{ | ||
public enum ProgressBarDisplayText | ||
{ | ||
Percentage, | ||
CustomText | ||
} | ||
|
||
class CustomProgressBar : ProgressBar | ||
{ | ||
//Property to set to decide whether to print a % or Text | ||
public ProgressBarDisplayText DisplayStyle { get; set; } | ||
|
||
//Property to hold the custom text | ||
public string CustomText { get; set; } | ||
|
||
public CustomProgressBar() | ||
{ | ||
// Modify the ControlStyles flags | ||
//http://msdn.microsoft.com/en-us/library/system.windows.forms.controlstyles.aspx | ||
SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); | ||
} | ||
|
||
protected override void OnPaint(PaintEventArgs e) | ||
{ | ||
Rectangle rect = ClientRectangle; | ||
Graphics g = e.Graphics; | ||
|
||
ProgressBarRenderer.DrawHorizontalBar(g, rect); | ||
rect.Inflate(-3, -3); | ||
if (Value > 0) | ||
{ | ||
// As we doing this ourselves we need to draw the chunks on the progress bar | ||
Rectangle clip = new Rectangle(rect.X, rect.Y, (int)Math.Round(((float)Value / Maximum) * rect.Width), rect.Height); | ||
ProgressBarRenderer.DrawHorizontalChunks(g, clip); | ||
} | ||
|
||
// Set the Display text (Either a % amount or our custom text | ||
string text = DisplayStyle == ProgressBarDisplayText.Percentage ? Value.ToString() + '%' : CustomText; | ||
|
||
|
||
using (Font f = SystemFonts.DefaultFont) | ||
{ | ||
|
||
SizeF len = g.MeasureString(text, f); | ||
// Calculate the location of the text (the middle of progress bar) | ||
// Point location = new Point(Convert.ToInt32((rect.Width / 2) - (len.Width / 2)), Convert.ToInt32((rect.Height / 2) - (len.Height / 2))); | ||
Point location = new Point(Convert.ToInt32((Width / 2) - len.Width / 2), Convert.ToInt32((Height / 2) - len.Height / 2)); | ||
// The commented-out code will centre the text into the highlighted area only. This will centre the text regardless of the highlighted area. | ||
// Draw the custom text | ||
g.DrawString(text, f, Brushes.Black, location); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.