'Locking Text Boxes'

  • Thread starter Thread starter ChrisM
  • Start date Start date
C

ChrisM

I have a Windows form in a C# project.

What I want to do under certain circumstances is to 'Lock' a text-box.
I know that I can do this by setting the Enable property to false, but this
greys it out.
Any suggestions as to the best way of making a TextBox read-only without
greying it out?

Regards,

ChrisM
 
Why dont you set focus elsewhere when it gets focus if your condition is
true

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP
 
Hi,

Well you could use KeyDown and set the Handled property to true, this
effectively means that you eat the keystroke, now even as this may solve
your problem it could confuse the user of the application, as he see that
the control is not greyout but he does not see his keystrokes in the control
it could think that your application has an error.

I think that the greyout is more commonly recognized as a control that
cannot be changed.


Cheers,
 
ChrisM said:
I have a Windows form in a C# project.

What I want to do under certain circumstances is to 'Lock' a text-box.
I know that I can do this by setting the Enable property to false, but this
greys it out.
Any suggestions as to the best way of making a TextBox read-only without
greying it out?

Set the ReadOnly property to true, but then set BackColor to
Color.White. (If you set Enabled to false, it will grey out the text -
and I can't find a way of getting round that.)
 
I agree. Good UI design would dictate that the box have some indication that
it is not editable.

-Eric
 
Thanks for you replys. I managed to answer my own question though.
I found the 'ReadOnly' property moments before 'Jons' post. (Thanks anyway!)
which greys the box but not the text. - thereby making it clear that the box
cannot be changed. I absolutly agree with 'Ignacio' and 'Eric' in this
thread that good UI design dictates that it should be indicated to the user
that the control is not editable.

Maybe I didn't make it clear, but the problem I had with the 'Enabled'
property is that it greys both the box AND the text, thereby making the text
difficult to read.

ChrisM
 
usally, i don't let others see it as a textbox and simply display it as a label of some sort
 
Back
Top