在我的 WPF 項目中,我有一個rectangle. -Color在運行時fill發生變化rectangle。如果用戶點擊rectangle,他應該得到rgb-values它rectangle。我知道我可以將其保存為Brush這樣:Brush brush = rectangle.Fill;但我不知道如何RGB從中獲取-值?我需要的是這樣的:labelRed.Text = brush.red;
labelGreen.Text = brush.green;
labelBlue.Text = brush.blue;
1 回答

慕神8447489
TA貢獻1780條經驗 獲得超1個贊
SolidColorBrush
您應該從屬性中獲取Fill
,然后從 中獲取 Color 結構SolidColorBrush
,現在 Color 對象具有和屬性R
?G
B
SolidColorBrush solidColorBrush = rectangle.Fill as SolidColorBrush;
if (solidColorBrush != null)
{
? ? Color color = solidColorBrush.Color;
? ? byte r = color.R;
? ? byte g = color.G;
? ? byte b = color.B;
? ? MessageBox.Show($"R{r}\nG{g}\nB");
}
- 1 回答
- 0 關注
- 382 瀏覽
添加回答
舉報
0/150
提交
取消