[英]Vertical Scrollbar color does not change
我是 C 的新手。 我创建了一个垂直滚动条(VScrollBar)。 我想改变滚动条背景颜色的颜色。 由于它是从 Control 继承的,所以当我更改颜色时,它不会产生任何效果。 在 InitializeComponents()->
this.vScrollBar1 = new System.Windows.Forms.VScrollBar();
this.vScrollBar1.Location = new System.Drawing.Point(472, -41);
this.vScrollBar1.Name = "vScrollBar1";
this.vScrollBar1.Size = new System.Drawing.Size(17, 80);
this.vScrollBar1.TabIndex = 15;
this.panel1.Controls.Add(vScrollBar1);
在构造函数中->
this.vScrollBar1.BackColor= Color.Black; //<--here is the back color property
this.Invalidate();
有什么建议么?
没有你想的那么简单,抱歉:(
Backcolor 属性从何而来?
You have to understand that System.Windows.Forms.VScrollBar inherits from System.Windows.Forms.ScrollBar that inherits from System.Windows.Forms.Control that got a Backcolor property.
为什么它不起作用?
System.Windows.Forms.ScrollBar 只是 Win32 API 提供的控件的包装。 此处不包括更改滚动条背景颜色。
该怎么办?
基本上你必须从 System.Windows.Forms.Control 继承并创建自己的滚动条控件。
文章: http://www.codeproject.com/Articles/41869/Custom-Drawn-Scrollbar
是的,这完全是人们喜欢 WPF 的原因。
请参阅我的回答,其中提到了支持自定义背景 colors 和主题https://stackoverflow.com/a/73613059/5514131的自定义 ScrollBar 控件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.