[英]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.