为什么我会得到与QUOT;控制不支持透明背景颜色和QUOT ;? [英] Why am I getting "Control does not support transparent background colors"?

查看:393
本文介绍了为什么我会得到与QUOT;控制不支持透明背景颜色和QUOT ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个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.

推荐答案

一个更好的方式是:

txtMyBox.BackColor = Color.Red;



你得到的,因为别的地方在你的代码,你试图设置正在导致错误窗体本身的背景颜色是透明的,不支持,仔细检查你的代码,你会发现财产以后这样的:

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:

BackColor = Color.Transparent;



由于没有元素名称(即myControl.BackColor =财产以后)和你的句子开始与背景色=财产以后 - 编译器认为要改变窗口的背景色组建成是透明的,请检查你的表单编辑过 - 你可以这样做,从那里

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:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        BackColor = Color.Transparent; //Control does not support transparent background colors.
    }
}

这篇关于为什么我会得到与QUOT;控制不支持透明背景颜色和QUOT ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆