I'm making a small paint program using wpf's inkcanvas and I've been trying to change the background colour in the c# code so the user will be able change it while it's running by adding RGB values. Could anyone give me an example or point me in the right direction?

有帮助吗?

解决方案 2

There are a lot of pre-made colors to use, which can be access as such

myInkCanvas.Background = Brushes.GhostWhite;

To adjust to your updated question

int r, g, b; 
//set r,g,b to something
myInkCanvas.Background = new SolidColorBrush(Color.FromArgb(255, (byte)r, (byte)b, (byte)b));

And for fun, if you have a hex string

myInkCanvas.Background = (Brush) new System.Windows.Media.BrushConverter().ConvertFromString("#FFFFFF90");

With separate hex string

myInkCanvas.Background = new SolidColorBrush(Color.FromArgb(0xff, 0xff, 0x90));

其他提示

theInkCanvas.Background = new SolidColorBrush(Color.FromRgb(r, g, b));
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top