diff --git a/CHANGELOG.md b/CHANGELOG.md index 069822ff3..e472ada1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ All notable changes to this project will be documented in this file. - [GUI] Minor tray icon improvements (#4231 by: HebaruSan) - [Multiple] Translation updates from Crowdin (#4233 by: vixnig38, ambition, tinygrox; reviewed: HebaruSan) - [Multiple] Cache migration and other fixes (#4240 by: HebaruSan) -- [Multiple] Start installing mods while downloads are still in progress (#4249 by: HebaruSan) +- [Multiple] Start installing mods while downloads are still in progress (#4249, #4255 by: HebaruSan) - [Multiple] Sort dependencies first in modpacks (#4252 by: HebaruSan) - [Multiple] Allow installs and removals to be cancelled (#4253 by: HebaruSan) diff --git a/GUI/Controls/LabeledProgressBar.cs b/GUI/Controls/LabeledProgressBar.cs index 48fcae5fb..0d864aafc 100644 --- a/GUI/Controls/LabeledProgressBar.cs +++ b/GUI/Controls/LabeledProgressBar.cs @@ -1,6 +1,7 @@ using System.Drawing; using System.Windows.Forms; using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; #if NET5_0_OR_GREATER using System.Runtime.Versioning; #endif @@ -18,19 +19,9 @@ public class LabeledProgressBar : ProgressBar public LabeledProgressBar() : base() { - SuspendLayout(); - - label = new TransparentLabel() - { - ForeColor = SystemColors.ControlText, - Dock = DockStyle.Fill, - TextAlign = ContentAlignment.MiddleCenter, - Text = "", - }; - Controls.Add(label); - - ResumeLayout(false); - PerformLayout(); + SetStyle(ControlStyles.OptimizedDoubleBuffer, true); + Font = SystemFonts.DefaultFont; + Text = ""; } [Bindable(false)] @@ -39,25 +30,33 @@ public LabeledProgressBar() [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] [EditorBrowsable(EditorBrowsableState.Always)] // If we use override instead of new, the nullability never matches (!) - public new string? Text - { - get => label.Text; - set => label.Text = value; + public new string Text { + get => text; + [MemberNotNull(nameof(text), nameof(textSize))] + set + { + text = value; + textSize = TextRenderer.MeasureText(text, Font); + } } + [Bindable(false)] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + [EditorBrowsable(EditorBrowsableState.Always)] // If we use override instead of new, the nullability never matches (!) - public new Font Font - { - get => label.Font; - set => label.Font = value; - } + public new Font Font { get; set; } - public ContentAlignment TextAlign + protected override void OnPaint(PaintEventArgs e) { - get => label.TextAlign; - set => label.TextAlign = value; + base.OnPaint(e); + TextRenderer.DrawText(e.Graphics, Text, Font, + new Point((Width - textSize.Width) / 2, + (Height - textSize.Height) / 2), + SystemColors.ControlText); } - private readonly TransparentLabel label; + private string text; + private Size textSize; } } diff --git a/GUI/Controls/TransparentLabel.cs b/GUI/Controls/TransparentLabel.cs deleted file mode 100644 index 5bbc63dc8..000000000 --- a/GUI/Controls/TransparentLabel.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using System.Drawing; -using System.Windows.Forms; -#if NET5_0_OR_GREATER -using System.Runtime.Versioning; -#endif - -namespace CKAN.GUI -{ - #if NET5_0_OR_GREATER - [SupportedOSPlatform("windows")] - #endif - public class TransparentLabel : Label - { - public TransparentLabel() - { - SetStyle(ControlStyles.SupportsTransparentBackColor - | ControlStyles.ResizeRedraw - | ControlStyles.Opaque - | ControlStyles.AllPaintingInWmPaint, - true); - SetStyle(ControlStyles.OptimizedDoubleBuffer, false); - BackColor = Color.Transparent; - } - - // If we use override instead of new, the nullability never matches (!) - public new string? Text - { - get => base.Text; - set - { - base.Text = value; - Parent?.Invalidate(Bounds, false); - } - } - - // If we use override instead of new, the nullability never matches (!) - public new ContentAlignment TextAlign - { - get => base.TextAlign; - set - { - base.TextAlign = value; - Parent?.Invalidate(Bounds, false); - } - } - - protected override CreateParams CreateParams - { - get - { - var cp = base.CreateParams; - cp.ExStyle |= (int)WindowExStyles.WS_EX_TRANSPARENT; - return cp; - } - } - - protected override void OnMove(EventArgs e) - { - base.OnMove(e); - RecreateHandle(); - } - - protected override void OnPaintBackground(PaintEventArgs e) - { - // Do nothing - } - } -}