textBox1.BackColor = Color.Cyan;
However, a problem arises when any transparent color (e.g. #00FEF2D4) is assigned to the BackColor property. Upon execution, a runtime exception will be thrown (see below).
textBox1.BackColor = ColorTranslator.FromHtml("#00FEF2D4");
On msdn, the following explanation is given:
The BackColor property does not support transparent colors unless the SupportsTransparentBackColor value of System.Windows.Forms.ControlStyles is set to true.
Using the control’s SetStyle() method, this SupportsTransparentBackColor value can be changed. The problem now is that SetStyle() is declared as a protected method and thus, only the control’s class or any child class can call this method.
A quick solution
A possible solution is to create a class inheriting from the control’s class. For example, a TransparentTextBox class can inherit from the System.Windows.Forms.TextBox. Now, the protected SetStyle() method is accessible and the SupportsTransparentBackColor value can be set to true. The ideal place to call the SetStyle() method will be in the constructor of this new class after the InitializeComponent() method calls.
It’s done. Now, as an instance of TransparentTextBox can be created and any transparent color can be set.
transparentTextBox1.BackColor = ColorTranslator.FromHtml("#00FEF2D4");
One major concern: do we really want to subclass all controls that probably will need a transparent color? Think...