簡體   English   中英

C#WPF將系統顏色設置為按鈕

[英]C# WPF set system color to button

我想將按鈕的背景色更改為系統顏色。 就像我在改變按鈕的顏色一樣

button2.Background = Brushes.Blue; 

變成藍色。 但是,我不希望將顏色更改為系統顏色。

您可以從System.Windows.SystemColors獲取系統顏色

button2.Background = System.Windows.SystemColors.MenuHighlightBrush;

WPF背景類型為System.Windows.Media.Brush。 您可以像這樣設置其他顏色:

// using System.Windows.Media;

button2.Background = Brushes.White;

button2.Background = new SolidColorBrush(Color.White);

button2.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0, 0);

您可以嘗試如下操作:

button2.Background = SystemColors.ActiveCaptionBrush;

SystemColors屬於System.Windows命名空間。

背景是畫筆類型。 但是您可以使用系統顏色創建純色畫筆並使用它。

SolidBrush systemColorBrush = new SolidBrush(systemColor); // Create SolidBrush from color
button2.Background = systemColorBrush;

我希望這有幫助

 <Button Background="{DynamicResource {x:Static SystemColors.DesktopBrushKey}}" Content="Hello, World!" /> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM