# VBForums CodeBank > CodeBank - Visual Basic 6 and earlier >  Simple Transparent Frame User Control v1.14

## Edgemeal

Just a simple transparent Frame (container) control.
Place control on a Form or inside a Picture box that has an image.

Properties: Caption, BackColor, BorderColor(XP/7 styles), FrameStyle, Font, ForeColor, ForeColorDisabled, Transparent, and Enable. 

v1.14 - Fix: Selecting a system color for XP\7 border color was always black.
v1.13 - Add option to disable transparency and set background color.
v1.12 - Add Windows XP/7 frame styles. (includes TabStrip Demo for XP Style)
v1.09 - Fix bugs in v1.06 to v1.08. (support and fix Framez inside of Framez)
v1.05 - General usage.

_Notes: 
Vista and Windows 7 have the same look for frames.
Transparency is now disabled by default in v1.13 and greater._

----------


## jmsrickland

Nice, real nice.

----------


## Edgemeal

v1.05 - 
Caption now changes as you type in design mode.
Simplified Font code.
Demo includes 2 pictures and how to update background of frames.

----------


## johnliang

hi,

I have a task to display a transparent user control that display gif / animated file. Currently I am using a webbrowser control in a user control.

But the problem is, the webbrowser doesn't have the transparent property. As such my gif file always has a solid white background, against the container's image background.

May I know what is the alternative ways?

Thanks and best regards,

----------


## jmsrickland

The WebBrowser does display transparent gif images. Are you sure your gif image has a transparent background? Post your gif image and I will test it with my WebBrowser

----------


## Edgemeal

> But the problem is, the webbrowser doesn't have the transparent property. As such my gif file always has a solid white background, against the container's image background.


For animated Gifs you might want to take a look at LaVolpe's Animated Image Control

----------


## jmsrickland

Program has error running in design mode.

Run-time error '398'
Client-Site not available



```
Private Function ManageTimers(ByVal Mode As Long) As Boolean

    If Mode = 0 Then
        If UserControl.Ambient.UserMode = True Then KillTimer c_tmrOwner c_tmrOwner, ObjPtr(Me)
        c_aniState = gfaStop
    Else
     '
     '
     '
     '
     '
End Function
```

----------


## Edgemeal

> Program has error running in design mode.
> Run-time error '398'
> Client-Site not available


Please use quotes so people reading your replies know who/what you are referring/replying to. 
I assume you are talking about LaVolpe's Animated Image Control I posted a link to, I don't get any errors like that here.

----------


## johnliang

Quote:
Originally Posted by *Edgemeal*
_For animated Gifs you might want to take a look at LaVolpe's Animated Image Control_

Thanks Edgemeal. It looked useful to me. Cheers.


Quote:
Originally Posted by *jmsrickland*
_The WebBrowser does display transparent gif images. Are you sure your gif image has a transparent background? Post your gif image and I will test it with my WebBrowser_

As requested, attached is the gif file. Thanks.

----------


## jmsrickland

Well I see that your gif is transparent (I can't test it because it is not the .gif file attached) but for a fact WebBrowser displays all transparent gif images as transparent so I don't know what your problem could be but if you can use LaVolpe's program then go for it.

----------


## johnliang

hi jmsrickland,

thanks for your help. my problem is i have created a uc which has a webbrowser control. this webbrowser control will display a gif animated file. 

secondly i have a picturebox which has a background picture. 

I put the webbrowser uc into this picturebox container. It is supposed to display the animated gif over the background picture. But instead, it displays the gif with a white solid background thereby covering the picturebox's background image.

Is there any solution?

Rgrds,

----------


## jmsrickland

Still not completely understanding this. 

OK, you have a UC. The UC has a WebBrowser Control in it. That is all, right? OK, the WebBrowser in the UC can display the animated gif correctly, right?

So now you take this UC and put it in a Picturebox which is on the parent Form, right?

The Picturebox already has a picture in it as the background. Now wouldn't putting the UC inside the Picturebox cover the background picture? I think so.

OK, here is where I get lost. Putting the UC inside the Picturebox. What do you expect it to do? The UC sits on top of the background picture of the Picturebox. Am I getting this wrong? But the gif image inside the WebBrowser still shows as a transparent image. What am I missing here?

----------


## johnliang

You are right on all your assumptions.

Basically I want the animated gif to be displayed on top of the picturebox with the picturebox's image as its background.

I see your point that the webbrowser (being not tranparent) will block the image of the picturebox underneath.

The reason I use put the webbrowser control on the uc is because I wish to be able to position the gif, to set the webbrowser scrollbars off and to display image in flat border mode (not 3D) during runtime, therefore using the uc to perform these functions.

All gif parameters are read from an external xml file.

----------


## jmsrickland

*Basically I want the animated gif to be displayed on top of the picturebox with the picturebox's image as its background*.

I think this is going to be a problem. As a rule, Pictureboxes do not have the ability to display a transparent gif image. There might be some code around here and perhaps the code is in LaVolpe's program that can *emulate*, so the speak, the effect of a transparent image in a Picturebox but I don't know what that code is but I bet there is some. But like I said, without some special technique you simply cannot display a transparent image in a Picturebox.

Why don't you make the WebBrowser's background the picture you want and put the animated gif on top of that? Wouldn't that work as well?  

Make your document like this....


```
<html>
<body background="background_picture.jpg">
<img src="animated.gif">
</body>
</html>
```

....and load this into the WebBrowser UserControl.

----------


## johnliang

thanks for all your constructive feedbacks. I will keep those comments in mind. 
you all have been very kind.

cheers.

----------


## broc028

Hi,

Nice Control, really useful.

Just one thing thou...

I am trying to include this frame in an activex control, but the redraw method does not seem to work. Do you have any ideas?

Thanks in advance!

----------


## Edgemeal

> Hi,
> 
> Nice Control, really useful.
> 
> Just one thing thou...
> 
> I am trying to include this frame in an activex control, but the redraw method does not seem to work. Do you have any ideas?
> 
> Thanks in advance!


Sorry for not replying sooner, I'm not sure I know the correct answer, my guess is the control you are putting my transparent framez UC into doesn't have the needed properties for the BitBlt call, like a .hDC, .ScaleMode, .ScaleX and .ScaleY.

I recently ran into that same problem and added this to my main container control.



```
Public Property Get hDC() As Long
    hDC = UserControl.hDC
End Property

Public Property Get ScaleMode() As ScaleModeConstants
    ScaleMode = UserControl.ScaleMode
End Property
```

see post #23 for the rest

----------


## Edgemeal

v1.06 & v1.07 didn't work correctly when put into a Picture Box, forgot to set AutoReDraw.

----------


## coolcurrent4u

> Sorry for not replying sooner, I'm not sure I know the correct answer, my guess is the control you are putting my transparent framez UC into doesn't have the needed properties for the BitBlt call, like a .hDC, .ScaleMode, .ScaleX and .ScaleY.
> 
> I recently ran into that same problem and added this to my main container control.
> 
> 
> 
> ```
> Public Property Get hDC() As Long
>     hDC = UserControl.hDC
> ...



Can you pls upload a copy of what you did for others 2 share

----------


## coolcurrent4u

> Just a simple transparent Frame (container) control.
> Place control on a Form or inside a Picture box that has an image.
> Properties: Caption, FrameStyle, Font, ForeColor, ForeColorDisabled and Enable.


The control doesnt seem to be transparent to me.

Place it on a tabstrip and compile with xp style to see what i mean

----------


## coolcurrent4u

> Sorry for not replying sooner, I'm not sure I know the correct answer, my guess is the control you are putting my transparent framez UC into doesn't have the needed properties for the BitBlt call, like a .hDC, .ScaleMode, .ScaleX and .ScaleY.
> 
> I recently ran into that same problem and added this to my main container control.
> 
> 
> 
> ```
> Public Property Get hDC() As Long
>     hDC = UserControl.hDC
> ...



Can you please place or upload a copy of what you did so i could see it. you said you got it to work.

----------


## Edgemeal

> The control doesnt seem to be transparent to me.
> 
> Place it on a tabstrip and compile with xp style to see what i mean


Might be easier if you uploaded a sample demo project of just that tabstrip with the xp style for me to play with.

----------


## Edgemeal

> Can you please place or upload a copy of what you did so i could see it. you said you got it to work.


Well the Framez control is in Pixel mode so I thought the above scaleX/Y code would work correctly but after trying some other controls inside the Framez (that call the scaleX/Y of its container) I noticed they weren't drawing correctly, so I changed the scaleX/Y code (Framez v1.09) and no longer need to check if a framez is inside another framez, so I guess my scalex/y properties above were wrong after all, at least for a UC that is set to pixel mode. 



```
Public Property Get ScaleX(Width As Single, FromScale As ScaleModeConstants, ToScale As ScaleModeConstants)
    ScaleX = UserControl.ScaleX(Width, FromScale, ToScale) / Screen.TwipsPerPixelX
End Property

Public Property Get ScaleY(Height As Single, FromScale As ScaleModeConstants, ToScale As ScaleModeConstants)
    ScaleY = UserControl.ScaleY(Height, FromScale, ToScale) / Screen.TwipsPerPixelY
End Property
```

I don't really get how UCs work, even though you set them to Pixel mode the cords act like they are in twips!

----------


## coolcurrent4u

can you pls post a project example that uses xp style and the tabstrip control. am still battleing with you code

----------


## Edgemeal

A vb tabstrip doesn't have a picture property nor does it have an .hDC that the Framez control needs.  I'm puzzled why you need the frame to be transparent since the tabstrip isn't a container with a pic property to begin with.

----------


## coolcurrent4u

the control is not a container

how do i make it one?

----------


## jmsrickland

You dont. You can place other controls on top of it but you cannot make it the parent.

----------


## coolcurrent4u

if i can't place controls on it, then its of no use.

----------


## Edgemeal

Well the TabStrip control is not a container but the MS Tabbed Dialog control is.

Why not just post a stripped down version of what it is you are trying to do so we can see it and maybe help better,  post it in the vb6 earlier forum.

----------


## coolcurrent4u

> Well the TabStrip control is not a container but the MS Tabbed Dialog control is.
> 
> Why not just post a stripped down version of what it is you are trying to do so we can see it and maybe help better,  post it in the vb6 earlier forum.


pls check this forum

http://www.vbforums.com/showthread.p...29#post3529829

----------


## Edgemeal

> pls check this forum
> 
> http://www.vbforums.com/showthread.p...29#post3529829


So far from what I can gather you want a transparent frame on top of a tabstrip control, but I can't understand why,  when using the TabStrip control you would set your controls .Zorder, .Visible, .Container, etc,etc, properties to show, move, hide the controls when the tabstrip index changes.

If you have objects/controls under the frame that you want to see you could just set their .Container property to the frame.

I can only guess you are taking the wrong approach to achieve the desired result.. You still haven't attached any sample project so I'm done trying to guess.

----------


## coolcurrent4u

ok here is a sample project

pls chk it out

----------


## Chris001

I can't see the project above, because I've done a hard drive format and haven't installed VB yet, but I guess you're having the same problem as what I had in the topic below.

http://www.vbforums.com/showthread.php?t=507336

Simply put a Picturebox with a white backcolor on the TabStrip and make the backcolor of the Frame white as well. You will only lose the gradient backcolor of the TabStrip, but I don't think anybody will notice (see the difference between first and third picture in the topic above).

----------


## coolcurrent4u

i am already using this solution, but its not good for a proffesional looking app. i would'nt have bothre about making a frame control transparent anyway

----------


## Edgemeal

Ok I think I see what you mean...,
When you apply the XP style to the form the TabStrip control actually has a gradient look to it and you want the Frame background to match the TabStrip background. 

The only way I can think of doing that besides what you already tried in the other thread would be to use a picbox (or usercontrol) and draw the same looking gradient effect onto it, then draw the borders and caption for a XP style looking frame on top of that.

----------


## Edgemeal

Even if you get your transparent frame effect working you'll also have to make other controls like check & option boxes appear transparent too, I know it's not impossible just seems like a lot of work/resources to use up instead of just going with a solid background color for everything. Best of Luck!

----------


## coolcurrent4u

can you send me this project to play with

----------


## Edgemeal

> can you send me this project to play with


Have fun playing.  :Smilie:

----------


## coolcurrent4u

thanks i'll play with it and see what i can do

can't i enable theme in ur control?

how do i do that

----------


## Edgemeal

> thanks i'll play with it and see what i can do
> 
> can't i enable theme in ur control?
> 
> how do i do that


No, if you look at the Framez code it just uses the DrawEdge API, thats one of the reasons I called it "Simple".  :Wink: 

I just slapped together another transparent Framez control real quick just to see if I could draw a XP looking one, it's nothing special, you'll probably want to look at sites like Planet Source Code for controls that support themes to learn from, there are a lot of controls on that site.

*EDIT* TabStrip_Experiment_2.zip Removed - Updates in Progress....
.

----------


## coolcurrent4u

thanks again

you have saved me from much trouble

i this i'll try this one

----------


## coolcurrent4u

oops you removed the code why?

----------


## Edgemeal

> oops you removed the code why?


Adding some properties to XP_Framez control, like Font, Colors, just a few basics. PM sent.

----------


## coolcurrent4u

ok thanks. waiting......

----------


## Edgemeal

> ok thanks. waiting......


Try this demo and let me know how it works out for you.

----------


## coolcurrent4u

thanks again for you bright idea

----------


## Edgemeal

Updated the Framez control to v1.12.
Added WinXP/Win7 to Frame Styles.
Also includes an updated demo of the TabStrip Experiment, the Windows XP frame style now looks correct.

----------


## Edgemeal

> thanks again for you bright idea


Glad I could help, though it looks great under WinXP that gradient look isn't used under Win7.

I was just playing with Windows 7 RC and the styles are different, the TabStrip no longer has that gradient look in its body, that area is all white. The Frames also look a little different, Win7 frames are single line too but with a less rounded corner. Not sure if it is the same way in Vista or not, haven't played with Vista much at all.

----------


## coolcurrent4u

windows 7 or vista? whats d difference am using xp

----------


## coolcurrent4u

so for win7 what do you suggest

----------


## Edgemeal

> so for win7 what do you suggest


If we wanted the tabstrip experiment project to match the OS (as close as possible) we'd first check to see what OS is running, if its Vista or Win7 then we don't apply the gradient to the pic box container and leave it as a solid white, and set the style of the v1.1.2 Framez control to Win7. 

I looked at some screen shots of Vista and Win7 and the tabstrip and frame look the same to me, though depending on the theme selected I'm sure the colors will change. If you really want your program to match the OS style at all times you really need to look at theme aware type controls, or possibly subclass so your project always knows if the theme/colors have changed and apply the needed changes to your controls.

----------


## coolcurrent4u

and just how do i do that?

you know i was just wandering if all this effort is not too much for just the frame control
remeber that the initial aim was to make the frame control look transparent. i had a code that does that but was slower when i had like three or four frame controls on a tabstrip

----------


## Edgemeal

> and just how do i do that?
> 
> you know i was just wandering if all this effort is not too much for just the frame control
> remeber that the initial aim was to make the frame control look transparent. i had a code that does that but was slower when i had like three or four frame controls on a tabstrip


Probably best if you search and ask those specific questions in the vb6 & earlier forum.

----------


## Merri

Also remember there are different themes available: the best way to go is to use the theme drawing APIs or hack around the default Windows controls (group box in this case), but that requires advanced knowledge and tricks.



```
Private Declare Sub GetMem4 Lib "msvbvm60" (ByVal Ptr As Long, Value As Long)

' ..

Dim lnghWnd As Long
GetMem4 ObjPtr(Frame1) + 68, lnghWnd
```

This is how you get the hWnd of the native VB frame (and actually any VB control that must have a hWnd in the first place).

----------


## coolcurrent4u

i got this themeing project from vbaccelerator but i don't know how to use it. the theming program is to help anyone doing themming

as regards theming which do you think would be better


app theming or windows theming

----------


## Merri

This relates to this topic a bit so I'm posting this here. I hacked around a bit to figure out if I could have an alpha transparent frame. I got it somewhat working but I don't have the time to play with this further.

Two issues: 1) the control does not move when the form is moved and 2) the z-index is lost, I don't know if it is possible to restore it while maintaining alpha transparency.

It is a hack that relies on SetParent, because normally you can't use SetLayeredWindow on a child window of another window, you can only use it to top level windows.

Start a new project, add Frame1 and paste:


```
Option Explicit

Private Const GWL_EXSTYLE = -20
Private Const GWL_STYLE = -16
Private Const LWA_ALPHA = &H2
Private Const WS_CHILD = &H40000000
Private Const WS_EX_LAYERED = &H80000

Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

Private Declare Sub GetMem4 Lib "msvbvm60" (ByVal Ptr As Long, Value As Long)
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Declare Function MoveWindow Lib "user32" (ByVal hWnd As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cX As Long, ByVal cY As Long, ByVal wFlags As Long) As Long

Private Sub Form_Resize()
    Static lngWnd As Long, udtRect As RECT, udtRectP As RECT
    Dim udtRectPN As RECT
    If lngWnd = 0 Then
        GetMem4 ObjPtr(Frame1) + 68, lngWnd
        GetWindowRect lngWnd, udtRect
        GetWindowRect Me.hWnd, udtRectP
        SetParent lngWnd, 0
        SetWindowLong lngWnd, GWL_EXSTYLE, GetWindowLong(lngWnd, GWL_EXSTYLE) Or WS_EX_LAYERED
        SetLayeredWindowAttributes lngWnd, 0, 50, LWA_ALPHA
        'MoveWindow lngWnd, udtRect.Left - udtRectPN.Left, udtRect.Top - udtRectPN.Top, udtRect.Right - udtRect.Left, udtRect.Bottom - udtRect.Top, 0
        SetParent lngWnd, Me.hWnd
    Else
        GetWindowRect Me.hWnd, udtRectPN
        udtRectPN.Left = udtRectP.Left - udtRectPN.Left
        udtRectPN.Top = udtRectP.Top - udtRectPN.Top
        'SetWindowLong lngWnd, GWL_EXSTYLE, GetWindowLong(lngWnd, GWL_EXSTYLE) And Not WS_EX_LAYERED
    End If
    SetWindowPos lngWnd, 1, udtRect.Left - udtRectPN.Left, udtRect.Top - udtRectPN.Top, udtRect.Right - udtRect.Left, udtRect.Bottom - udtRect.Top, 0
End Sub
```

Happy hacking if someone catches this up and tries to get it to work.


*Edit!*
It still doesn't maintain zindex, but it is possible to have the transparent window behind other controls! Now the hard part is tracking window movement...

----------


## Edgemeal

> Happy hacking if someone catches this up and tries to get it to work.


This would be a sort of a cool effect for disabling a frame since you can't click on any of the controls inside the frame when you apply this code.

----------


## seba.kwiat

Framez doesnt support tooltiptext for labels does anyone know how to fix this issue?
I need that label for making check boxes and option boxes transparent.
Instead of tooltiptex from label i could show tooltiptext of check box or option if i know how to do that programically.

thx

----------


## Edgemeal

> Framez doesnt support tooltiptext for labels does anyone know how to fix this issue?
> I need that label for making check boxes and option boxes transparent.
> Instead of tooltiptex from label i could show tooltiptext of check box or option if i know how to do that programically.
> 
> thx


That problem doesn't have anything to do with the Framez control in particular, if you create a new usercontrol and set it as a container you'll see the lable control (even if set to opaqe) doesn't show it's tooltip, though I'm not sure why.

Unless someone knows why and a solution I'd suggest trying something else for your tooltips, like a ballon tooltip class (copy of the class posted here) instead. You wont have that problem with labels then and have nicer looking tooltips also IMO. 

btw, to use a label with that class you would pass the labels container handle since a label doesn't have a handle.

----------


## seba.kwiat

> That problem doesn't have anything to do with the Framez control in particular, if you create a new usercontrol and set it as a container you'll see the lable control (even if set to opaqe) doesn't show it's tooltip, though I'm not sure why.
> 
> Unless someone knows why and a solution I'd suggest trying something else for your tooltips, like a ballon tooltip class (copy of the class posted here) instead. You wont have that problem with labels then and have nicer looking tooltips also IMO. 
> 
> btw, to use a label with that class you would pass the labels container handle since a label doesn't have a handle.


Thanks for your reply.

you can not use that class because labels has no hwnd but i solved the problem by placing the label inside the picturebox. I set the labels to transparent and i cut out picturebox from the backgrount so it all looks transparent and tooltip works fine on that.

----------


## Edgemeal

> you can not use that class because labels has no hwnd


You can use that tooltip class on labels, as I said you need to use the *labels container hWnd*.

I use this sub to set/show the tooltip, then use it like this...


```
' Lable1 inside Framez1 control...
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    ShowToolTip  "ToolTip Here", Framez1.hWnd, "Title Here"
End Sub
```

*EDIT* btw, The Framez control posted here doesn't have a MouseMove event, which you'd most likely need so you can reset that balloon tip class.
Add a simple MouseMove event to the Framez control...


```
' General Declares
Event MouseMove()

' code
Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    RaiseEvent MouseMove
End Sub
```

----------


## Edgemeal

Updated:
v1.14 - Fix(v1.12): Selecting a system color for XP\7 border color was always black.
v1.13 - Add option to disable transparency and set background color.
_Note: Transparency is now disabled by default in v1.13 and later._

----------


## ohailo

can you tell me how to apply it in my form if ever i want it to apply on my own form please?

----------


## ohailo

can you tell me how to apply it in my own form...i try'd to add your ActiveX Control but its not working it keeps my frame in my form untransparent...what should i do?..please help me

----------


## seba.kwiat

> can you tell me how to apply it in my own form...i try'd to add your ActiveX Control but its not working it keeps my frame in my form untransparent...what should i do?..please help me


you have to add this control to your controls then you will see new control which you apply on the form the same way as the others eg. label etc.

cheers

----------


## edhanz

Hi Edgemeal,

i played with your TabStrip Demo For WinXP. i like this, but actually i wanted my form is resizeable and the tabstrip and the frame as well. but when i use Form_Resize, then the frame is error, saying Can't create AutoRedraw image..

is there a way to solve this?
thank you very much..

----------


## Edgemeal

> Hi Edgemeal,
> 
> i played with your TabStrip Demo For WinXP. i like this, but actually i wanted my form is resizeable and the tabstrip and the frame as well. but when i use Form_Resize, then the frame is error, saying Can't create AutoRedraw image..
> 
> is there a way to solve this?
> thank you very much..


Might want to upload a demo of your code, in the meantime here is  a quick re-size test I did and didn't see that problem.

----------


## edhanz

yes it works as i wanted..  :Big Grin: 
thank you very much..

----------

