Skip to content

Commit

Permalink
Fixed a crash which happened if the user disabled visual styles e.g. …
Browse files Browse the repository at this point in the history
…with the 'Windows Classic' theme of Windows 7.
  • Loading branch information
FireEmerald committed May 31, 2017
1 parent f851bfd commit aa48697
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions SoundSwitch.UI.UserControls/TextProgressBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,18 @@ protected override void OnPaint(PaintEventArgs e)
var rect = ClientRectangle;
var g = e.Graphics;

ProgressBarRenderer.DrawHorizontalBar(g, rect);
rect.Inflate(-3, -3);
if (Value > 0)
// Validate that the user has enabled visual styles in the operating system
if (ProgressBarRenderer.IsSupported)
{
// As we doing this ourselves we need to draw the chunks on the progress bar
var clip = new Rectangle(rect.X, rect.Y, (int)Math.Round(((float)Value / Maximum) * rect.Width),
rect.Height);
ProgressBarRenderer.DrawHorizontalChunks(g, clip);
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
var 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
Expand All @@ -69,7 +73,6 @@ protected override void OnPaint(PaintEventArgs e)
break;
}


using (var f = new Font(FontFamily.GenericSansSerif, 8.25F))
{
var len = g.MeasureString(text, f);
Expand Down

0 comments on commit aa48697

Please sign in to comment.