如何在 C# 中将禁用的 TextBox 的当前文本颜色设置为其当前背景颜色?
简单地执行 txt Lala.ForeColor = txt Lala.BackColor 似乎不起作用。
最佳答案
这个有效:
txtLala.Text = "Red";
txtLala.BackColor = System.Drawing.Color.Red;
txtLala.ForeColor = txtLala.BackColor;
txtLala.ReadOnly = true;
尝试在 readonly
之前设置 color
。还要检查你是如何设置颜色的!
编辑
试试这个
txtLala.Attributes.Add("style","background-color:Red;color:Red");
如果你想让它不可见,你知道你可以将它设置为
txtLala.Visible = False;
编辑二
我终于试过了
txtLala.Enabled = false;
...你看到那个灰色的阴影颜色!我不认为你可以搞砸它,它看起来是一个浏览器属性设置。
为什么不设置为ReadOnly
或Visible = False
?
也许你有充分的理由 Enabled = false
但你应该注意:
Use the Enabled property to specify or determine whether a control is functional. When set to false, the control appears dimmed, preventing any input from being entered in the control.
Note The ability to enable or disable functionality is always available. However, dimming and locking the control only works in Microsoft Internet Explorer version 4 and later.
This property propagates down the control hierarchy. Therefore, disabling a container control will disable all child controls within that container.
Note Not all controls support this property. See the indivual controls for details.
关于c# - 将禁用的 TextBox 的 ForeColor 设置为与其在 C# 中的 BackColor 相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/362603/