views:

73

answers:

5

In win forms controls, there are two properties : ReadOnly and Enabled.

Can someone give me any information about what the difference between these two properties are. I feel like they behave the same way.

+5  A: 

As it says in the following forum post:

In the context of a TextBox, readonly allows the user to set focus to and select and copy the text but not modify it. A disabled TextBox does not allow any interaction whatsoever.

Use ReadOnly when you have data that you want the user to see and copy, but not modify. Use a disabled textbox, when the data you are displaying is not applicable in for the current state of a dialog or window.

Taken from: MSDN Forums

Jamie Keeling
You hvae the answer below, I will only add that you can always set `disabled`, but not all controls have a `readonly` tag, which is a pity. I advise you not to mix them on one page (without good reason), as it might confuse a user.
LeonixSolutions
A: 

Enabled specifies whether user interaction is allowed. If a control is disabled then it will not generate any UI events.

ReadOnly determines whether the user can edit the contents of the control. For example, a ReadOnly TextBox cannot be edited, but you can still click on it, select the text contained within it, etc.

robinjam
A: 

ReadOnly I generally associate with a TextBox or other control that contains text; it dictates whether or not the user can modify the text displayed by the control. The user can still select the text, though (e.g., to copy and paste it into another program).

Enabled basically controls whether or not any user interaction with the control is possible. For instance a Button with Enabled == false cannot be clicked; a CheckBox with Enabled == false cannot be toggled, etc. Note that a TextBox with Enabled == false also cannot have its text selected (that would be user interaction).

Furthermore, controls with Enabled == false do not raise events related to user interaction such as Click.

Dan Tao
A: 

If you take a text box with a scrollbar as an example, ReadOnly does not allow the user to edit text, but the scrollbar is still active (think about licence boxes in installation programs). Enabled = false will cause the entire control to disable, not just the text editing area.

AJ
A: 

Some controls, e.g., buttons, can only be enabled or disabled. A disabled control will give a visual indication that it cannot be interacted with right now (typically by graying/fading out). Others can also be read-only, in that they can be interacted with in some way but not edited. For example, an up-down control is often like that, which means you can press the buttons to change the value but not edit it by normal typing. (It's also possible to have controls that you can never interact with but which are still usefully disable-able; a label can still be grayed out as part of indicating that a whole area of the GUI is not usable right now, which is a more pleasing visual effect than just changing the controls that are interactive.)

It's virtually always the case that being disabled implies that a control is also read-only. I've seen a few cases where that wasn't true, and it always felt more like a bug than anything else to me. It's best to regard the states as representing a tri-state value where one of the states is not used for some controls.

Donal Fellows