cannot change backcolor of scrollbar in Winforms app
according to MS there must be property scrollbar.backcolor but cannot find it.
Any ideas ??
cannot change backcolor of scrollbar in Winforms app
according to MS there must be property scrollbar.backcolor but cannot find it.
Any ideas ??
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Tahir AnsariRank #366 · 6.8K reputationPosted Oct 27, 2023, 1:27 AM EDT
In Windows Forms (WinForms) applications, the
ScrollBarcontrol does not have aBackColorproperty by default. This means that you cannot directly change the background color of aScrollBarby setting itsBackColorproperty.you can work around this limitation by creating a custom
ScrollBarcontrol by inheriting from the existingScrollBarcontrol and overriding theOnPaintmethod to draw your custom background color.using System; using System.Windows.Forms; public class CustomScrollBar : VScrollBar { public CustomScrollBar() { this.SetStyle(ControlStyles.UserPaint, true); this.BackColor = Color.Blue; // Set your desired background color } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); using (SolidBrush brush = new SolidBrush(this.BackColor)) { e.Graphics.FillRectangle(brush, e.ClipRectangle); } } }we create a custom
ScrollBarcontrol namedCustomScrollBarand set itsBackColorproperty to the desired background color. We then override theOnPaintmethod to draw the background color as a rectangle. You can replaceColor.Bluewith your preferred background color.boris salnikovRank #2,400 · 589 reputationPosted Oct 27, 2023, 8:54 AM EDT
Thanks