简体   繁体   English

垂直滚动条颜色不变

[英]Vertical Scrollbar color does not change

I am a newbie in C sharp.我是 C 的新手。 I created a vertical scrollbar (VScrollBar).我创建了一个垂直滚动条(VScrollBar)。 I wanted to change the color of the scrollbar's Backcolor.我想改变滚动条背景颜色的颜色。 As it is inherited from Control, when i changed the color it does not take any effect.由于它是从 Control 继承的,所以当我更改颜色时,它不会产生任何效果。 In the InitializeComponents()->在 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);

In the Constructor->在构造函数中->

this.vScrollBar1.BackColor= Color.Black;     //<--here is the back color property
this.Invalidate();

Any Suggestions?有什么建议么?

Not as simple as you might think, sorry:(没有你想的那么简单,抱歉:(

Where does the Backcolor property come from? 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. 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.

Why doesn't it work?为什么它不起作用?

The System.Windows.Forms.ScrollBar is just a wrapper around the control provided by the Win32 API. System.Windows.Forms.ScrollBar 只是 Win32 API 提供的控件的包装。 Changing the Scrollbar Backcolor is not included there.此处不包括更改滚动条背景颜色。

What to do?该怎么办?

Basicly you have to inherit from System.Windows.Forms.Control and create your own scrollbar control.基本上你必须从 System.Windows.Forms.Control 继承并创建自己的滚动条控件。

Articles: http://www.codeproject.com/Articles/41869/Custom-Drawn-Scrollbar文章: http://www.codeproject.com/Articles/41869/Custom-Drawn-Scrollbar

Yep, that is totally a reason why people prefer WPF.是的,这完全是人们喜欢 WPF 的原因。

See my answer mentioning a custom ScrollBar control that supports custom background colors and themes https://stackoverflow.com/a/73613059/5514131请参阅我的回答,其中提到了支持自定义背景 colors 和主题https://stackoverflow.com/a/73613059/5514131的自定义 ScrollBar 控件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM