Re: Transparent Container?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



kk, you are right about the wacky behavior of the labels when used in a
transframe (new word:)) that is inside a non-transframe. I have about 8
labels in the transframe and 7 of them are invisible (for the reason
you explained) but 1 is visible, but it is acting as the original
label, meaning the opaque background is still there, tooltip, etc.

I'll just be patient and wait for you to work your magic on a later
version. :) I just get antsy and am always trying to move forward, lol.

The reason I tested the frame-inside-a-frame thing is because (aside
from just using a pic on the main form) I also very often use the
original tab control that is part of mscomctl.ocx which I then use an
indexed set of frames for each tab to switch through using zorder, and
since each frame then becomes the *** for the tab, I can color the
frame and do other design things to it, then could put the transframe
on that tab as well.

Anyway, thanks for all of your effort! :)

Mike Williams wrote:
"AppleBag" <applebag@xxxxxxxxx> wrote in message
news:1155302289.584382.69220@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

I have been toying with the code and sort of battle testing
to see if I could throw it some loops . . . . .

Yikes! It's just some testbed code at the moment. Don't be throwing things
at it, at least not yet ;-)

and came across some issues when placing a transparent frame
inside another non-transparent frame. The labels are acting wacky.

Well they will be. The code works by setting up a clipping region that
effectively make the entire Frame area transparent so that all you see is
whatever happens to be underneath it (normally the Form). It then runs
through the Form's Control Collection checking each control to see if its
Container is the Frame, in which case it causes the small area occupied by
that specific control to effectively be non-transparent, so that you can see
the control. (For simplicity of description, and for want of a better
phrase, I called the act of doing that "punching a non-transparent hole").
That works for all controls except transparent Labels, because the way VB
draws those things causes the Label's transparency to cease to have an
effect and you see the Label as though it was set to Opaque. So, in order to
get around that problem, the code causes the Label to become invisible by
the simple act of failing to "punch the non-transparent hole" at its
position. That causes whatever is beaneth the Label (the Form in the
example) to show itself. Then the code draws the Label's caption property
onto the Form using the Print method (although later it would be best to use
the DrawText API instead, for reasons I've already explained). So, as it
currently stands, in order for the routine to work properly you need to pass
it a Form (so that the routine will know which Control Collection to look
at) and a Frame so that it knows what "container" to look for when running
through the Control Collection. If you place your "transparent Frame" inside
another Frame (as you have suggested) then in the transparent areas you will
see the other Frame, not the Form. Also, and this is what you probably mean
when you say "The labels are acting wacky", you will not see the Label
caption. This is because it isn't really a Label caption at all, but is
simply some text that has been drawn to the underlying Form using the Print
statement, and it will of course be hidden by "the other Frame" into which
you dropped your "transparent Frame".

To summarise, for this code to work as it stands you need to have the
"transparent Frame" in a Form (something to which you can draw text) and not
in another Frame. Actually, that's not strictly true because it would be
possible to make a very slight adjustment to the code so that it draws
(Prints) the text to the "transparent Frame's" container (it currently draws
to the Form which you pass it). In that way you could have the "transparent
Frame" in a container other than the Form. However, as the code currently
stands, it needs to be a container into which you can Print stuff using the
VB Print method, such as a Form or a Picture Box.

Having said all that, almost nothing is impossible of course and after the
code has been modified so as to use the TextOut (or better still DrawText)
API method it should be possible use another Frame as a container for the
"transparent Frame" and to draw to the hDC of the underlying Frame instead
of to the underlying Form, although you would also need to add a bit more
code to make the drawing of the text persistent. I'm not sure how all that
would work in practice, but I think it is quite probably "doable". For the
moment though I would simply place your "transparent Frame" directly onto
the Form, unless there is some pressing reason for you to need to do
otherwise.

Mike Williams (MVP - Visual Basic)

.


Quantcast