Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 362
Refracted Paladin Avatar asked Nov 27 '22 00:11

Refracted Paladin


2 Answers

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.

like image 156
t3rse Avatar answered Jan 10 '23 16:01

t3rse


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".

like image 27
Romias Avatar answered Jan 10 '23 15:01

Romias