Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting "Control does not support transparent background colors"?

Tags:

c#

winforms

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.

like image 840
Brian Hooper Avatar asked Dec 21 '22 21:12

Brian Hooper


1 Answers

Quite old post but... Have you tried this before?

public partial class MyForm : Form
{
    public MyForm()
    {
        this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);

        InitializeComponent();
    }
}
like image 102
Luiz Duarte Avatar answered Dec 23 '22 10:12

Luiz Duarte