Created
July 24, 2023 18:12
-
-
Save CamelCaseName/fe893e8c80d3f008012cf64cc75356dc to your computer and use it in GitHub Desktop.
C# Winforms Progressbar without Animation and custom color
This file contains hidden or 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
using System.Drawing; | |
using System.Windows.Forms; | |
namespace CustomComponents | |
{ | |
/// <summary> | |
/// A extended WinForms ProgressBar which has a different colour and removes the animation. | |
/// </summary> | |
public class NoAnimationBar : ProgressBar | |
{ | |
/// <summary> | |
/// The constructor for said Progressbar, mimics the WinForm constructor. | |
/// </summary> | |
public NoAnimationBar() | |
{ | |
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true); | |
} | |
/// <summary> | |
/// A override for the OnPaint method to draw the bar without an animation and a custom colour. | |
/// </summary> | |
/// <param name="e">The PaintEventArgs to manipulate.</param> | |
[System.Runtime.Versioning.SupportedOSPlatform("windows")] | |
protected override void OnPaint(PaintEventArgs e) | |
{ | |
e.Graphics.FillRectangle(new SolidBrush(ForeColor), new Rectangle(0, 0, (int)(Width * (float)Value / Maximum), Height)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment