I am working on a C# – Winforms application and attempting to set the background colour of a read-only text box like so…
txtMyBox.BackColor = Color.FromName ("Red");
This is failing with the error message…
System.ArgumentException was unhandled
Message=Control does not support transparent background colors.
Source=System.Windows.Forms
First things first; is this the right way to set the background colour for a read-only textbox? I’m doing this a lot for ordinary textboxes and it appears to work fine.
If it is, could someone help me out with what a “transparent background color” is, and why I should want one? I don’t think I do; I just want the background to change colour.
A better way would be:
The error you getting is being caused because of somewhere else in your code where you are trying to set the background color of the form itself to be transparent and that is not supported, check your code carefully and you will find somthing like that:
Since there is no element name (i.e. myControl.BackColor = somthing) and your sentence start with BackColor = somthing – the compiler thinks you want to change the background color of the windows form into being transparent, check your form editor too – you might doing that from there.
Here is a reproduction of your error: