How to change the font color of a disabled TextBox?
NOTE: see Cheetah's answer below as it identifies a prerequisite to get this solution to work. Setting the BackColor
of the TextBox
.
I think what you really want to do is enable the TextBox
and set the ReadOnly
property to true
.
It's a bit tricky to change the color of the text in a disabled TextBox
. I think you'd probably have to subclass and override the OnPaint
event.
ReadOnly
though should give you the same result as !Enabled
and allow you to maintain control of the color and formatting of the TextBox
. I think it will also still support selecting and copying text from the TextBox
which is not possible with a disabled TextBox
.
Another simple alternative is to use a Label
instead of a TextBox
.
How to change font-color for disabled input?
You can't for Internet Explorer.
See this comment I wrote on a related topic:
There doesn't seem to be a good way,
see:
How to change color of disabled html controls in IE8 using css
- you can set the input toreadonly
instead, but that has other
consequences (such as withreadonly
,
theinput
will be sent to the server
on submit, but withdisabled
, it won't
be): http://jsfiddle.net/wCFBw/40
Also, see: Changing font colour in Textboxes in IE which are disabled
I want to change the font color of a disabled input
You can add this CSS class in your styles.scss file :
For label
.mat-form-field-appearance-outline.mat-form-field-disabled.mat-form-field-label {
color: rgba(0,0,0,.6)!important;
}
For input value
.mat-form-field-type-mat-native-select.mat-form-field-disabled .mat-form-field-infix::after, .mat-input-element:disabled {
color: rgba(0,0,0,1)!important;
}
Disabled Textbox Font Colour
You could use the .locked
property, like so
Private Sub UserForm_Click()
custom_lock Me.TextBox1
End Sub
Private Sub UserForm_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
custom_unlock Me.TextBox1
End Sub
Function custom_lock(tb As MSForms.TextBox)
tb.ForeColor = vbRed
tb.Locked = True
End Function
Function custom_unlock(tb As MSForms.TextBox)
tb.ForeColor = vbBlack
tb.Locked = False
End Function
Change the font color of disabled input text box?
There is no way to do it - what you can do instead though is change the input to readonly:
<input class="TextBoxAsLabel" data-val="true" data-val-number="blah" readonly="readonly" id="Total" name="XTotal" type="text" value="$0.00" />
This will give you the disabled functionality but preserve styling :)
See this post for more details: How to change font-color for disabled input?
Hope This Helps.
Change a textbox colour when disabled C#
When a TextBox is disabled, it ignores the ForeColor
. You can override this by implementing your custom painting.
From the source Thread:-
You can override the OnPaint event like something like this:-
protected override void OnPaint(PaintEventArgs e)
{
SolidBrush drawBrush = new SolidBrush(ForeColor);
// Draw string to screen.
e.Graphics.DrawString(Text, Font, drawBrush, 0f,0f);
}
set the ControlStyles to "UserPaint"
public MyTextBox()//constructor
{
// This call is required by the Windows.Forms Form Designer.
this.SetStyle(ControlStyles.UserPaint,true);
InitializeComponent();
// TODO: Add any initialization after the InitForm call
}
CSS: How to change font color for a specific disabled field?
Switch the input
selector for your ID
:
#thisOne[disabled=disabled] { color: #fff !important; background: red;}
<input id="thisOne" disabled="disabled" value="Lorem ipsum">
<input id="notThisOne" disabled="disabled" value="Lorem ipsum">
Related Topics
Htmlagilitypack -- Does <Form> Close Itself for Some Reason
How to Embed an Application Manifest into an Application Using VS2008
Performing Inserts and Updates with Dapper
Can You Configure Log4Net in Code Instead of Using a Config File
Getting a System.Type from Type's Partial Name
ASP.NET Urlencode Ampersand for Use in Query String
How to Pinvoke to Getwindowlongptr and Setwindowlongptr on 32-Bit Platforms
Reading Excel Files as a Server Process
C# Create/Modify/Read .Xlsx Files
Why Does C# Limit the Set of Types That Can Be Declared as Const
How to Use Switch-Case on a Type
How to Detect a Process Start & End Using C# in Windows
Why Cannot Ienumerable<Struct> Be Cast as Ienumerable<Object>
Change Color and Font for Some Part of Text in Wpf C#
Datagrid Get Selected Rows' Column Values
How to Get the Lowercase Name of an Object, Even When Null, in C#