I need to change the background colour of a button using C# code (Visual Studio 2008).
I saw some people recommending the inclusion of a directive: using System.Windows.Media; – I tried it and it triggered this error: Windows does not exist in namespace System. I tried several combinations like:
btn.BackColor = Color.Red;
btn.Background = Brushes.Green;
And neither is working. Is a special directive needed for using colour? What code do you suggest. Thanks a lot.
This should change your button background color to Red
You need to include System.Drawing namespace as Color class belongs to that. Like this
And ofcourse you need to add the reference to
System.DrawingDLL in your project to use this namespace and Color class.