473,404 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

'Locking Text Boxes'

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
Nov 15 '05 #1
5 8431
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"ChrisM" <hi****@AskMeIfYouWantIt.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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

Nov 15 '05 #2
Why dont you set focus elsewhere when it gets focus if your condition is
true

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP
"ChrisM" <hi****@AskMeIfYouWantIt.com> wrote in message
news:#d**************@tk2msftngp13.phx.gbl...
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

Nov 15 '05 #3
ChrisM <hi****@AskMeIfYouWantIt.com> wrote:
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.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4
I agree. Good UI design would dictate that the box have some indication that
it is not editable.

-Eric
Nov 15 '05 #5
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

"ChrisM" <hi****@AskMeIfYouWantIt.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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

Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jack | last post by:
Hi, I need advise as to how to do the following. In a asp page, the user can input information via text boxes which goes to a database. If users click a check box named final and submit the asp...
7
by: Gertjan van Heijst | last post by:
Hi, I really hope someone can help me because I've already spend 2 days on this problem and I'm not getting anywhere. I think the problem is that I don't really understand how text boxes store...
2
by: John Kreps | last post by:
(acc 2002) I've got six unbound text boxes on a subform that has a white background. Each of those six boxes has an expression that when true, will change its background from white to another...
2
by: Gary | last post by:
Hello All, I have an editable data grid in my web form, this grid allows the user to add new records, edit existing records and also delete them. When a user adds a record the grid goes in to...
11
by: Edson Peacock | last post by:
I have a report with sub reports, one of the subreports have 12 text boxes that are 2" high and I want them all to grow if one goes to 3" high. If anyone has any suggestions they are very much...
6
by: BurntWithTime | last post by:
Hello everyone, Please can anyone tell me if it is possible for a VB.NET application to check a database and then create textboxes on a form that correspond to those records on the database? For...
6
by: =?Utf-8?B?Sm9obiBBdXN0aW4=?= | last post by:
I have an app that displays about 20 items of data in text boxes. Very occasionally I need to allow these to be used for data entry, but the bulk of the time they are solely for information. They...
6
by: noe1818 via AccessMonster.com | last post by:
Just a quick question about lines: Is it possible to connect a text box (e.g. txtbx1 to txtbx2 and txtbx2 to txtbx3) with lines where txtbx1,2,&3 move up or down according to their values? Like...
11
by: jwessner | last post by:
I have a form (Form1) which contains basic Project data and a subform listing the personnel assigned to the Project as a continuous form. Selecting a person on that project and clicking on a command...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.