Real value of "Visible" property?

  • Thread starter Thread starter Michael Kremser
  • Start date Start date
M

Michael Kremser

Hi NG!

If you put a control on a tab page and you set its "Visible" property to
"True" and you select another tab page, the "Visible" property returns
"False", because the control is currently not visible to the user. But
other controls whose "Visible" property you set to "False" also return
"False", so "False" is not "False"... :-/

If one derives from a control, it´s possible to override SetVisibleCore
and store the bool argument to know whether the control is intended to
be visible to the user. But I don´t want to have an own control just for
that purpose. Also it would be possible to handle the "VisibleChanged"
event which is only fired if the "Visible" property *really* changes,
but I have a form with 24 text controls and I don´t want to store that
in an extra array or so.

So, is there a trick to find out whether a control is *intended* to be
visible and not if it is actually visible to the user?

To demonstrate this, I made a little project:

http://www.mkcs.at/dev/VisibleProperty.rar

Best regards,

Michael
 
Michael said:
Hi NG!

If you put a control on a tab page and you set its "Visible" property
to "True" and you select another tab page, the "Visible" property
returns "False", because the control is currently not visible to the
user. But other controls whose "Visible" property you set to "False"
also return "False", so "False" is not "False"... :-/

Annoying, isn't it.
If one derives from a control, it´s possible to override
SetVisibleCore and store the bool argument to know whether the
control is intended to be visible to the user. But I don´t want to
have an own control just for that purpose. Also it would be possible
to handle the "VisibleChanged" event which is only fired if the
"Visible" property *really* changes, but I have a form with 24 text
controls and I don´t want to store that in an extra array or so.

So, is there a trick to find out whether a control is *intended* to be
visible and not if it is actually visible to the user?

It doesn't look like there's a way, unless something was added in 2.0. The
intended visibility is a bit field in a private member variable that stores
a grab-bag of such things, but there's no way to directly query the state.

It looks like if you set the control's parent to null, then query the
Visible property, then restore the parent, you might actually see the
"intended visible" state - I'm not sure what other undesirable effects that
might have since it'll cause the parent to remove and then re-add the
control to it's Controls collection, firing off events in the process -
sounds risky to me but it might be something to try.

-cd
 
Carl Daniel [VC++ MVP] schreef:
Michael Kremser wrote:

Annoying, isn't it.

Indeed. :-/
It doesn't look like there's a way, unless something was added in 2.0. The
intended visibility is a bit field in a private member variable that stores
a grab-bag of such things, but there's no way to directly query the state.
Oh.

It looks like if you set the control's parent to null, then query the
Visible property, then restore the parent, you might actually see the
"intended visible" state - I'm not sure what other undesirable effects that
might have since it'll cause the parent to remove and then re-add the
control to it's Controls collection, firing off events in the process -
sounds risky to me but it might be something to try.

I have to try this out. Thanks a lot for your hint!

Best regards,

Michael
 
Back
Top