PDA

View Full Version : Transparent User form with Visible Controls



oxicottin
12-09-2012, 06:24 AM
Hello, I am using Excel 07 and have been searching for days and am getting bits and pieces of information on this subject and cant seem to either get a good example or I get something that don't work. What I want to do is create a userform that would have userforms Title Bar/Forms Frame hidden and the forms background set to 65% Opacity but have all the userforms controls not transparent just the forms background. I found code that with make everything transparent but I cant find it what would let me skip the transparency on the controls.

Any thoughts or samples?


Thanks,
Chad

GTO
12-09-2012, 07:54 AM
I believe that you cannot, as the controls are not really their own windows. Thus, they 'belong' to the form and operations against the form (such as setting transparency) affect everthing that belongs to the form.

Mark

oxicottin
12-09-2012, 12:55 PM
I have found an example and this guy figured it out but I have no clue how they did it and there is a lot of extra code that I wouldn't use. They have mouse over buttons and A LOT of eye candy. Could someone take a look? Thanks!

I cant post a link yet due to the 5 post limit so your going to have to copy and paste and add the beginning of the link then the rest is below :( I just dont want to post a couple stupid questions just to get 5 posts under my belt.

h t t p s//w w w . xtremevbtalk.com/showpost.php?p=1347012&postcount=10

Aflatoon
12-10-2012, 06:31 AM
if you don't need to be able to move the form, then the code in the form is just:
Option Explicit
Private m_objCFormSkin As CFormSkin 'For transparancy

Private Sub UserForm_Initialize()

''''Form Transparency
Set m_objCFormSkin = New CFormSkin
Call m_objCFormSkin.Form_Initialize(Me, RGB(178, 31, 114))

End Sub
Private Sub UserForm_Activate()
Call m_objCFormSkin.Form_Activate
End Sub
Private Sub UserForm_Terminate()
Set m_objCFormSkin = Nothing
End Sub


and leave the class as it is

oxicottin
12-10-2012, 07:06 AM
Thank you for the reply, I entered your VBA and I get a error when decompileing.

(User-Defined type not defined) @ m_objCFormSkin As CFormSkin

I haven't used any of the VBA code from the example link given I was just refering to it because the gentelman had achieved it somehow. What I wanted to do is I already have the UserForm transparent and completely border-less is there a way I can set the transparency for selected controls on my userform to 255. Possibly by using the controls tag or something. as of right now the entire form and its controls are the exact same transparency. And I am going to add the functionally of moving the form I just haven't figured it out yet.

Thanks,
Chad


Here is my module:
Option Explicit

'************************************************************************** **************************************************'
'******************************** /REMOVE USERFORM FRAME START\ ********************************'
'*** /TRANSPARENT BACKGROUND START\ ***'
'***
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Private Declare Function DrawMenuBar Lib "user32" (ByVal hWnd As Long) As Long

Private Declare Function GetActiveWindow Lib "user32" () As Long

Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" ( _
ByVal hWnd As Long, ByVal lngWinIdx As Long, ByVal dwNewLong As Long) As Long

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" ( _
ByVal hWnd As Long, ByVal lngWinIdx As Long) As Long

Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Integer, _
ByVal bAlpha As Integer, ByVal dwFlags As Long) As Long

Private Const WS_EX_LAYERED = &H80000
Private Const LWA_COLORKEY = &H1
Private Const LWA_ALPHA = &H2
Private Const GWL_EXSTYLE = &HFFEC

Dim hWnd As Long
Dim bytOpacity As Byte
'*** ***'
'*** \REMOVE USERFORM FRAME END/ ***'
'******************************** \TRANSPARENT BACKGROUND END/ ********************************'
'************************************************************************** **************************************************'

Sub SemiTransparent()

'\\Call SemiTransparent to set userforms background to 150 transparent
'bytOpacity can be set to (=255 No Transparency to (=0 full transparent)

bytOpacity = 150
Dim lngWinIdx As Long
hWnd = GetActiveWindow
lngWinIdx = GetWindowLong(hWnd, GWL_EXSTYLE)
SetWindowLong hWnd, GWL_EXSTYLE, lngWinIdx Or WS_EX_LAYERED
Call SetLayeredWindowAttributes(hWnd, 0, bytOpacity, LWA_ALPHA)

End Sub

Sub Borderless()

'\\Call to get rid of UserForm border

Dim Style As Long, Menu As Long
hWnd = GetActiveWindow
Style = GetWindowLong(hWnd, &HFFF0)
Style = Style And Not &HC00000
SetWindowLong hWnd, &HFFF0, Style
DrawMenuBar hWnd

End Sub

Aflatoon
12-10-2012, 07:14 AM
The form in the sample you linked to does all of that. Just remove the controls you don't need - keep the label as its there to give you a means to drag the form - and the mouseup/mousedown code for them as well as their setup routines.

oxicottin
12-10-2012, 07:22 AM
I didn't want to have all the unnecessary code that I have no idea what it goes to or what it does I would like to learn a little about what im doing by either copy and pasting into my own worksheet because I research and try to figure out how it works and write alot of notes in the code on what and where it came from and what its does. Can you point me in the right direction on what to grab from the example to incorporate into mine?

Thanks,
Chad


Oh, I forgot to mention.... I dont care about the mousing over to change image I just want selected controls to be not transparent.

Aflatoon
12-10-2012, 07:43 AM
Download the file, keep the class module-there doesn't appear to be any real unnecessary code in there from a quick glance so I am not sure to what you are referring-and remove the controls from the form other than the label for dragging (appropriately named) and the code relating to them. There is no additional code required to keep visible any controls you add to the form thereafter.