Groups | Blog | Home
all groups > dotnet windows forms > february 2008 >

dotnet windows forms : "Locked" controls?


Olaf Rabbachin
2/14/2008 10:04:46 AM
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,
Teemu
2/14/2008 4:51:01 PM

"Olaf Rabbachin" <Olaf_NoSpam@IntuiDev.com> kirjoitti viestissä
news:u5A%23kiubIHA.4712@TK2MSFTNGP04.phx.gbl...
[quoted text, click to view]

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

I've used this method with textboxes.

-Teemu
Olaf Rabbachin
2/14/2008 7:53:03 PM
Hi,

[quoted text, click to view]

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

Cheers,
Teemu
2/14/2008 9:04:29 PM

"Olaf Rabbachin" <Olaf_NoSpam@IntuiDev.com> kirjoitti viestissä
news:uKByUrzbIHA.1208@TK2MSFTNGP03.phx.gbl...
[quoted text, click to view]

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
Teemu
2/14/2008 9:06:24 PM

"Teemu" <tsirkia@hotmail.com> kirjoitti viestissä
news:2h0tj.296927$Z23.116892@reader1.news.saunalahti.fi...
[quoted text, click to view]

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
Olaf Rabbachin
2/15/2008 9:56:32 AM
Hi,

[quoted text, click to view]

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,
AddThis Social Bookmark Button