View Full Version : Non-editable edit control?

01-08-2007, 07:43 PM
Is there any way to make a control that looks like a TEdit (one-line textbox) on screen, but can only display data, not receive keyboard focus? Setting the ReadOnly property isn't enough; that still allows you to select the text. What I'm looking for is basically a label that looks exactly like a TEdit.

(The reason for this is that the edit box displays modifiable data that can be edited, but only by changing a value elsewhere; editing it directly would cause problems, and allowing it to receive focus while not being editable would cause confusion. Better to just make it non-editable, but still look like a TEdit to make its nature as a box that holds modifiable data clear.)


01-08-2007, 08:20 PM
You have three relatively easy options (that I can think of now).

a) Use a TEdit, set the readonly property to true and the enabled property to false. The text is greyed, but the control cannot receive focus.

b) Use a TStaticText. It can be configured to have a border and the background colour can be changed. It looks similar to TEdit but not exactly like it.

c) Use a combination of a TPanel (to give the border style and background colour) and a TLabel. Nasty, but it would probably end up looking like an enabled TEdit the most.

They are the three easy options I can think of off the top of my head.

01-08-2007, 08:31 PM
An easier option is to put a TEdit on a TPanel and then set the enabled property of the TPanel to false.

Now you cannot select the TEdit but it still looks correct - white with black text.

Set the panel's bevelinner and bevelouter to bvnone

16-08-2007, 05:46 AM
Hey masonwheeler,

How did you get on? There has been no reply.

16-08-2007, 12:39 PM
I've been on here regularly, watching. I just haven't replied to this thread yet. :P