Windows application with Readonly controls
Hello,
I am trying to develop a windows application with readonly controls on it, where each user must click "Edit" to access and modify data. The onlu readonly control is textbox, but both checkbox and combobox are not. The enabled property looks ugly and it's light visible. I have tried to put a transparent image above all cotrols so user cannot acces them, but tranparency does not work well in visual studio. My last thought was to create my own controls, but i am wondering is there is a better way to lock my data fiels.
Thanks Stefanos
[636 byte] By [
OratIos] at [2008-1-10]
I see. Your original post wasn't very clear: Text boxes are the only control with the ReadOnly property. I thought you were saying that the only control you needed to set as readonly was a text box.
You can't do it directly with other controls, but you can cheat: in the event handlers for your check boxes and combo boxes, force the value back to what the original value in the backing store is.
You can also create an inherited control; all you'd have to do then is declare a public bool property for ReadOnly. Then, override the OnClick event and check the ReadOnly value; when it's true, mark the event as handled but don't actually let the value change. (Or just change it back to whatever value it was before it was changed.)
You may have to track the original value, but that's pretty simple.
Inherited controls are really very simple, you just declare a public class that inherits the control you want to change, like this:
public class MyCheckBox
inherits CheckBox
....
I can do a more complete example tomorrow; I was just heading for bed when I got your reply.