亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

獲取 WPF 中填充矩形的 RGB 顏色

獲取 WPF 中填充矩形的 RGB 顏色

C#
人到中年有點甜 2023-08-20 14:54:36
在我的 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?GB

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");

}


查看完整回答
反對 回復 2023-08-20
  • 1 回答
  • 0 關注
  • 382 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號