tags:

views:

546

answers:

10
+2  Q: 

Text Box vs Labels

I am developing a winForm App in C# and I have come across something that has always bothered me.

Is it better practice to use a Label or a TextBox when displaying data to the user.

Things like Name, Phone #, etc. My gut says to use a TextBox and just set it to read-only until the time comes that I need to allow editing from that particular spot. Plan for the future, as it were.

As a young Lone Wolf developer I would really appreciate any insight here. Are there any pro's and con's to either? Is there something else I am not thinking of?

Thank you in advance for your time.

+1  A: 

Use a label unless the data needs to be edited. You really should use whatever tag is most appropriate for the info being shown.

mabwi
+3  A: 

Indicating that a value is dynamic is the key here. Usually a text box makes this easy to recognize which is why it is used. If you can do that with a label it would be preferred.

Joe Philllips
+2  A: 

For static text I always use labels - why use a heavier control if I don't need it?

Jim Anderson
+5  A: 

One useful thing to consider is that text in a textbox is selectable so it's easier for your users to copy/paste the content.

Premature optimizations like using labels because they are more light weight should take a backseat to defensive programming that, as you suspect, could save you time in the future.

David in Dakota
Interesting. I would consider using a textbox because "you may want to make the text editable in the future" premature optimization.
Jim Anderson
+1 for considering the user! How many times have you encountered some inscrutable error message which you had to re-type by hand into Google because the developer used a label control / message box to display it rather than something that can be Ctrl+A, Ctrl+C'd?
Matt
+2  A: 

Labels are the way to go.

the problem with a textbox that's not enabled is a user expects there's some way to enable it. If they can't find a place to allow editing then they think something is wrong with the software.

Keith Nicholas
+1  A: 

At times, your users might want to be able to highlight and copy static text (addresses, phone numbers, etc). As far as I know, Labels cannot be highlighted, whereas read-only Textboxes can.

tehblanx
+1  A: 

I agree with d03boy. Textbox infers that the value is edittable. Labels infer display-only form. It s a bit more work. IMHO, you want your application to match other windows based applications to make your app feel as professional as it can be.

I'd follow the view/edit form display model.

asp316
+4  A: 

For data that the user can edit (whether it's enabled in the current context or not) I always use a text box which I enable/disable as needed. For data that is purely informational, i.e. the user will not be given the option in the current context to change it, then that's where I use a label.

JMD
+1  A: 

I think this is a place where you need to stop being a programmer and start being a user. Look at things as if you were the user of the system, not the developer. See which one makes you feel more comfortable as a user. If necessary (and possible), ask people who aren't involved with the development process and aren't much into the technicalities of programming.

Mussnoon
A read-only textbox shouldn't appear any different to a user than a label. Most end-users will not even know the difference.
Jim Anderson
+3  A: 

You may need to allow user COPY the text... that is the only reason I use Textboxes and then make them look as Labels (readonly and transparent background and no borders).

In fact, the "Properties" dialog in Windows uses Textboxes to allow you to copy the text.

NOTE that I said "ReadOnly"... not "Disabled".

Romias