Read Only property affects TextBox formatting

Joined
Dec 10, 2007
Messages
18
Location
Florida
Programming Experience
Beginner
Hello all,
The problem I am having is that I have a textbox that I have set the readOnly property to true. I have set the foreColor of that textBox to red but, the text remains black.
When I take off the read Only property then my text becomes red which is what I want but, I want the read Only property enabled as well. Does anybody know how to have a textBox with the ReadOnly property = True, and then be able to format the textBox with lets say

VB.NET:
 TextBox.Text = Variable.ToString("C").

for currency and then change the text ForeColor to red.

VB.NET:
TextBox.ForeColor = Color.Red

As well as put a parenthesis around the text. I figure this:

VB.NET:
TextBox.Text = "(" & Variable.ToString("C") & ")"

I checked MSDN but when under ReadOnly property it says that :

"The ReadOnly property only affects user interaction at run time. You can still change text box contents programmatically at run time by changing the Text property of the text box."

But any changes I make to the text do not show in run-time.
 
It says Text property, it doesn't say ForeColor property. The readonly appearance of the textbox control is supposed to tell the user intuitively that the textbox is in readonly mode. However, exceptions exist, when it is blatantly obvious that the box is supposed to be readonly, like a chat log display for instance, you may control the keyboard input instead to make it 'readonly', as in this example for a RichTextbox.
 
i tried adding a textbox to an empty app. then set it as readonly, + changed the forecolor to red - nothing happened. so i changed the backcolor to black - bingo - forecolor = red. i changed the backcolor back to control - still forecolor = red.

so you might have to do something along those lines? try this

VB.NET:
TextBox1.ForeColor = Color.Red
TextBox1.BackColor = SystemColors.Control
 
Back
Top