Link to home
Start Free TrialLog in
Avatar of DanAvni
DanAvniFlag for Israel

asked on

using the win2k transparency

i know that win2k & up has the ability to set a windows transparency to be semi transparent. how can i set this on a VB6 label or picturebox? i have a form that displays a picture. my user needs to define a hotspot of a rectangular shape. i want to display to him the hotspot as a semi transparent area. i use for the hotspot a label (i can change it to picturebox if needed)
Avatar of samsonite1023
samsonite1023

You can only use the transparency on top level windows, and your picture box is a child of the form it's on.

There is a complicated way around this, which would be setting the picturebox's parent as the desktop, and moving the picturebox to above your form (so it looks like it is part of it).

For transparency, I recommend downloading a class for it, as it is much easier to use and the coding is already done. Also, you must use something that has a window handle (labels do not), like a picturebox.

Hope this helps!
Avatar of DanAvni

ASKER

do you know of such a class that i can d/l?
ASKER CERTIFIED SOLUTION
Avatar of samsonite1023
samsonite1023

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here is code to make the picture box a top level and translucent.  You can move it around by setting the picture1.left and picture1.top properties, just like you would normally.

Hope this helps!

Add to a form, in a project that has the CTranslucentForm class.

Private Declare Function WindowFromDC Lib "user32" (ByVal hdc As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long

Dim trans As CTranslucentForm

Private Sub Form_Activate()
Set trans = New CTranslucentForm
Dim pictureHWND As Long
'get the picture box's hwnd
pictureHWND = WindowFromDC(Picture1.hdc)
'make it a top level window
SetParent pictureHWND, GetDesktopWindow
'make it translucent
trans.hWnd = pictureHWND
trans.Alpha = 200
End Sub


There you go

-Sam
Avatar of DanAvni

ASKER

samsonite1023 thx for your help. although i did not test the code you sent me it seems that it will work. we have decided at a system review meeting to change some things in the app and they will also result in the ability to display polygons transparently through an OCX we wrote.

thx again for your help!