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?
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.
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".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With