简体   繁体   English

当readonly设置为true或false时,什么控制textBox背景颜色

[英]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.

相关问题 如何设置文本框只读属性 true 或 false - How to set a textbox readonly property true or false 将一组文本框控件更改为ReadOnly = false - changing a group of textbox controls to ReadOnly = false 当TextBox ReadOnly设置为“ True”时,为什么ASP.NET Ajax ColorPickerExtender控件不返回任何内容? - Why ASP.NET Ajax ColorPickerExtender control returns nothing when the TextBox ReadOnly set to “True”? 将IsReadOnly设置为true时,为什么会忽略TextBox.Background的值? - Why is the value for TextBox.Background ignored when IsReadOnly is set to true? 是否有一种LINQy方法将所有ReadOnly控件的TabStop设置为false? - Is there a LINQy way to set all ReadOnly controls' TabStop to false? ASP.NET中的ReadOnly = true和TextBox1.Attributes.Add(“readonly”,“readonly”)有什么区别? - What is the difference between ReadOnly=true and TextBox1.Attributes.Add(“readonly”, “readonly”) in ASP.NET? WPF-设置为只读时,TextBox无法正确绑定 - WPF - TextBox not binding properly when set to readonly 如果背景已更改,文本框不使用只读颜色 - TextBox Not using Readonly color if background has been changed 只读文本框的背景 - background for a ReadOnly TextBox 只读为true时无法获取gridview文本框值 - unable to get gridview textbox value when readonly is true
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM