Question

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?

Était-ce utile?

La solution 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));

Autres conseils

theInkCanvas.Background = new SolidColorBrush(Color.FromRgb(r, g, b));
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top