垂直滚动条颜色不变 [英] Vertical Scrollbar color does not change

查看:34
本文介绍了垂直滚动条颜色不变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 C 语言的新手.我创建了一个垂直滚动条(VScrollBar).我想更改滚动条背景色的颜色.由于它是从 Control 继承的,当我更改颜色时,它不会产生任何效果.在 InitializeComponents()->

I am a newbie in C sharp. I created a vertical scrollbar (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. In the 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();

有什么建议吗?

推荐答案

没你想的那么简单,抱歉 :(

Not as simple as you might think, sorry :(

Backcolor 属性从何而来?

您必须了解 System.Windows.Forms.VScrollBar 继承自 System.Windows.Forms.ScrollBar,而 System.Windows.Forms.ScrollBar 继承自具有 Backcolor 属性的 System.Windows.Forms.Control.

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 提供的控件的包装器.此处不包括更改滚动条背景色.

The System.Windows.Forms.ScrollBar is just a wrapper around the control provided by the Win32 API. Changing the Scrollbar Backcolor is not included there.

怎么办?

基本上,您必须从 System.Windows.Forms.Control 继承并创建您自己的滚动条控件.

Basicly you have to inherit from System.Windows.Forms.Control and create your own scrollbar control.

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

是的,这完全是人们喜欢 WPF 的一个原因.

Yep, that is totally a reason why people prefer WPF.

这篇关于垂直滚动条颜色不变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆