Change the text color of a disabled text field

Hi everybody,

I have a beginner question. I have several texfields in a form that are initially disabled and therefore the color of the text is light gray. The question is, is it possible to change the text format of the disabled fields? (or it can only be light gray). I have a edit pushbutton that enables the fields and changes the color of the text to normal (black). I would like to keep the color of the text regardless of whether the state of those textfields is enabled or disabled.

Could someone help me, please?

Thank you very much.

Sergio

What is your visual cue to your user that these fields are disabled? If there is no visual cue and the only way they find that out is to try and type in them, then don’t disable the fields, but prevent typing into them by returning true in the keyDown event.

Thanks Roger for your suggestion but I see two problems to use keydown event:

  1. I do not want the cursor shape to change, the field to have the focus and I can put the cursor “to write” inside the field.

  2. I have two popup-menus in my form and I do not want the menu can be displayed in the preview mode (only that you see the selected value).

I tried to use the readonly property but this is not available for the popupmenu.

Any other suggestion?

Sergio

I’m confused at this point as to what you are going for. You didn’t answer my question. Is there any visual representation to the user that the textField in question is disabled?

Set the Control as ReadOnly ?

Ok, yes, I want the user to see the difference when editing the record. Maybe you can understand me better if you see an example.

Screencapture

Is this for web? Can you use a style and change the text color to what you want? Maybe change some CSS?

Usually, and by default, the color change is to indicate that you can or can’t change something.

Just tested for macOS desktop and it looks like “disable” take the text color and make it lighter. So my guess is that you can’t have, at least on desktop, the same color for enable and disable elements.

My example is for Desktop. As Alberto says, I would like to differentiate between the elements enabled or disabled but not only in color. I would like to avoid that the user can edit the textfields if the edit pushbutton is not activated. I have got this effect with the enable event but I think the light gray does not look good (no highlights) and I would change it to a different font format.

Set the color to what ever you want… and in the GOTFOCUS event, move the focus to somewhere else instead… this way the control stays “alive” and “active” but the user can never get to it.

Ok, I don’t know what you refer as “no highlights”, but if you want to use different color to gray, you can change that, the only issue is that it will be a lighter color. So you can disable the textfield and assign a different color.

Will something like this work for you?

Thank you so much Alberto and Dave for your help. Alberto I have tested to change only the color (in the textfield disabled) but I don’t like so much. Still not seeing the text too well when the textfield is disabled.
I’m going to test the Dave’s option with the GOTFOCUS event. Dave, could you explain in more detail how to implement this event? What text code would I have to add once I created the gotfocus event in a textfield?. Could you show me an example, please?.

The “problem” with Dave’s recommendation is that the cursor will change between an arrow and ‘input text icon’ (don’t know if that’s called). But yes it will keep the color that you put there and not lighter.

I don’t know if TextField is a native control (that the OS controls the behavior) so there will not be any option to change the lighter color. If it is a custom control, maybe you can request a feature to be able to set how light (or not) you want the color when disabled.

Edit: haven’t learn about MouseEnter events or changing the pointer, maybe you can use that event to change the pointer to what you want during the GotFocus if you don’t want it to change to the input text pointer?

You will get something like this:

The difference with ReadOnly is that you can’t select the text because SetFocus is send elsewhere, but the user could try and for a split second the text background will change.

Note: this is on mac, I don’t know if you want it on windows and how this work there.

try setting the cursor to invisible as well

Thank you Dave, I learned about cursors today. I think this is what Sergio wants:

Or maybe change the color when “disabled”

Great Alberto!!, I want something like you show in your last answer but I don’t know how to implement the gotfocus event. I have selected the textfield and have added the gotfocus event but, what do I have to write inside gotfocus event to get it disabled?.

Please I need your help!!!

Alberto… glad I was able to point you in a direction that caused you learn something new. I’d rather teach people to fish, than serve up a fish dinner :slight_smile:

Sergio, what I did is add a boolean property, change the value if I need the textfield enable/disable and on GotFocus check the boolean to SetFocus elsewhere.

Used the same property with MouseEnter to change the cursor to what I wanted.

Note: for me the original disable is good enough and no need for extra code, but this shows that it can be done, I just had to learn more things to make it work

Thanks Alberto, I have an integer property (as your boolean property) to set enable/disable status and following your instructions I have added this code in the gotfocus event: (0 disabled / 1 enabled)

[code]If mEditarStatus = 0 Then

labelField.SetFocus // I don’t know where to set the focus

Else

Me.SetFocus

End If
[/code]

With this code I don’t get your result. What’s wrong?

I don’t know if a label can have the focus. Maybe you can use another textfield that can have the focus or think outside the box and create a not-needed textfield or other control that can get the focus.

I learn by testing different things. I know that there are many ways to do things and because I’m relative new to programming/Xojo I believe there are better to do things that what I find.

I hope with this information you can find a solution. If you can’t I can share what I did in more detail. Just know that is not the “best” way to do things.