Declare Function GetClassLong Lib "user32" Alias "GetClassLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Const GCL_STYLE = -26&
Const CS_CLASSDC = &H40
Const CS_OWNDC = &H20
If (GetClassLong(childHwnd, GCL_STYLE) And (CS_CLASSDC Or CS_OWNDC)) = 0 Then ' can use WS_EX_LAYERED
Note: In order to use layered child windows, the application has to declare itself Windows 8-aware in the manifest
Updated: 27 Feb 2011
Added OpacityPercent property to control. Allows picturebox to appear between 0% to 100% opaque.
--------------------------------------------------------------------------------------------------------------
The attached usercontrol and module will allow a picturebox to fake transparency very well. It can also fake transparency for any option buttons and checkboxes contained within the picturebox. Labels are your responsibility, simply set their backstyle property to transparent.
How to use the usercontrol and module. The module is used for subclassing only.
Subclassing will only be used if checkboxes or option buttons are to be made to fake transparency.
1) Simply add them to your project. It was not designed as a stand-alone ocx
2) Add one usercontrol for each picturebox you want to fake transparency
3) Picturebox borders are up to you. Control will work with/without them
4) On form_load, assign the usercontrol its picturebox via the AttachBuddy function
5) Read the short comments at the top of the control's code for more details.
Sample with themed controls
Some notes. As already mentioned, subclassing is only in play if you opt to make checkboxes or option buttons fake transparency.
Using gradient backgrounds might be a good example, but using textured backgrounds and placing text over them can be hard on your users' eyes. I, for example, am very color blind. Captchas over textured backgrounds drive me nuts. So would your app if it had similar appearance.
Also, you should test your app with and without a manifest (themed controls). For example, you may lose your text forecolor with themed controls. So placing a checkbox with white text over a very dark background looks good un-themed, but text may become invisible when themed. Keep this in mind, you may want 2 different color schemes. You can call the ValidateThemeEmployed function.
Limitations for the ucPicBuddy
1) One ucPicBuddy per picturebox. It must exist on the same form as the picturebox. The ucPicBuddy control will move itself appropriately.
2) Do not place any non-windowless controls between the picturebox and its container (i.e., form, frame, other picturebox)
-- picturebox looks transparent but is not. Placing controls behind it will not allow you to click on them & they won't show through
3) You can place any windowless controls between the picturebox and its container. They will show through & are not clickable.
4) You should ensure the picturebox and its ucPicBuddy control have synchronized .Visible property settings to avoid unnecessary paints
5) Option buttons/checkboxes with .Style property = Graphical are not supported
6) Some actions at runtime require you to refresh what changed: Form's BackColor, Option Button/CheckBox caption at runtime
7) Changing option button/checkbox .Alignment property at runtime requires you to call the AttachChildControl to re-add it to the ucPicBuddy control.
-- This is because VB destroys that checkbox/option button & recreates a new one with the new Alignment property
.
Last edited by LaVolpe; Mar 4th, 2015 at 10:23 AM.
Reason: added the Side Note
Insomnia is just a byproduct of, "It can't be done"