c# - 将禁用的 TextBox 的 ForeColor 设置为与其在 C# 中的 BackColor 相同

标签 c# .net user-interface

如何在 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;

...你看到那个灰色的阴影颜色!我不认为你可以搞砸它,它看起来是一个浏览器属性设置。

为什么不设置为ReadOnlyVisible = 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/

相关文章:

c# - 在 LINQ 中加入匿名类型

design-patterns - 物体应该自己画吗?如何? (我使用的是 android,但问题适用于所有 OO 语言)

c# - WIN32_Processor::ProcessorId 是否对所有计算机都是唯一的

C# DataTable删除行

c# - .NET 中的程序集绑定(bind)问题

c# - 未知数据类型的 Object.CompareTo(Object)

c# - 修改其值后两种不同类型的输出存在歧义?

c# - foreach 父类(super class)列表中的继承(子类)对象

objective-c - Controller 是否应该知道iOS应用程序中的NSManagedObjectContext

android - Android 的垂直信息流 View 的确切小部件是什么?