"Locked" controls?

O

Olaf Rabbachin

Hi everybody,

in a VB.Net (VS 2005) application, there is basically three "states" in
which controls are to signal what can be done with them. Usually, values
loaded into controls may be looked at, but not edited ("Locked"). In
certain cases (simplest: user has the permission to change data), controls
allow changing their contents. While certain operations are being carried
out, controls are completely disabled (i.e. the form itself has its
Enabled-property set to <False>).

Thus I need a way of at least visually distinguishing between <.Enabled =
False> and i.e. <"Locked" = True>. The easiest way would be to have
controls appear exactly as the <.ReadOnly> property does - the controls'
background appears grayed out, but the forecolor remains black. This also
enhances readability and copying text or seeing the tooltip is also
possible.
Too bad this property can only be found in some controls but not even for
some the most usual ones, i.e. TextBox and DataGridView have it, but
ComboBoxes and DatePickers don't.

The <EnabledChanged> event didn't help either, as setting the forecolor of
the resepective control seems to not be considered when the control is
disabled.

Any idea how I could realize something like a <ReadOnly> appearance for
controls that themselves do not publish that property?

Cheers & TIA,
Olaf
 
T

Teemu

Olaf Rabbachin said:
Hi everybody,

in a VB.Net (VS 2005) application, there is basically three "states" in
which controls are to signal what can be done with them. Usually, values
loaded into controls may be looked at, but not edited ("Locked"). In
certain cases (simplest: user has the permission to change data), controls
allow changing their contents. While certain operations are being carried
out, controls are completely disabled (i.e. the form itself has its
Enabled-property set to <False>).

Thus I need a way of at least visually distinguishing between <.Enabled =
False> and i.e. <"Locked" = True>. The easiest way would be to have
controls appear exactly as the <.ReadOnly> property does - the controls'
background appears grayed out, but the forecolor remains black. This also
enhances readability and copying text or seeing the tooltip is also
possible.

Have you tried to change the background color after setting .ReadOnly=True?

I've used this method with textboxes.

-Teemu
 
O

Olaf Rabbachin

Hi,
Have you tried to change the background color after setting .ReadOnly=True?

I've used this method with textboxes.

I'm talking about implementing something like .ReadOnly for controls that
do *NOT* publish that property.

Cheers,
Olaf
 
T

Teemu

Olaf Rabbachin said:
Hi,


I'm talking about implementing something like .ReadOnly for controls that
do *NOT* publish that property.

Cheers,
Olaf

Could you create own class which inherits for example from TextBox and set
it .ReadOnly=True and set backcolor to white? Override those properties and
make them read only. Then it would be possible to create controls you like.

-Teemu
 
T

Teemu

Teemu said:
Could you create own class which inherits for example from TextBox and set
it .ReadOnly=True and set backcolor to white? Override those properties
and make them read only. Then it would be possible to create controls you
like.

-Teemu

Sorry, I just figured out what you meant. You need this for property for
controls that doesn't have it. I thought you wanted to create read only
controls with that setting hidden from users.

-Teemu
 
O

Olaf Rabbachin

Hi,
Sorry, I just figured out what you meant. You need this for property for
controls that doesn't have it. I thought you wanted to create read only
controls with that setting hidden from users.

actually I'd like to avoid having to create inherited controls as the
project is pretty large and it could get very costly to provide/use a
growing number of such controls. I was thinking that there has to at least
be some way of managing to override the system-provided forecolor that is
being used when a control has its .Enabled-property set to false. While
this will not allow the user to copy the control's contents or see the
tooltip, it would at least allow for visually distinguishing between
control-states.

But thanks anyway! :)

Cheers,
Olaf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top