[英]What controls a textBox background color when readonly is set to true or false
Usually when we set readonly true or false in a textbox, the background automatically switches into grey or white. 通常,当我们在文本框中设置readonly为true或false时,背景会自动切换为灰色或白色。
But, on my code, in some specific cases I wanna have to turn the background red, or green, etc. for a moment, and later I want it to behave normaly. 但是,在我的代码上,在某些特定情况下,我想暂时将背景变成红色或绿色,等等,之后我希望它表现得很正常。
The problem is that after I set the background to red, when I change the readonly setting, the color won't change back into grey or white, I've been using the following code to get it to grey (read only), but I want it to auto change the color as it used before. 问题是,当我将背景设置为红色后,当我更改只读设置时,颜色不会变回灰色或白色,我一直在使用以下代码将其设置为灰色(只读),但是我希望它自动更改以前使用的颜色。
textBox1.BackColor = Control.DefaultBackColor;
If you wanna reset the way the BackColor is set, you simply use the following method 如果您想重置BackColor的设置方式,只需使用以下方法
textBox1.ResetBackColor(); textBox1.ResetBackColor();
And it will turn the background to white or grey accordingly to read only again 并且它将背景相应地变为白色或灰色以再次读取
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.