PDA

View Full Version : Don't have Frame1 & ListBox1 BackColor = fmBackStyleTransparent Property?



Erdin? E. Ka
01-05-2007, 03:40 PM
Hi everyone, :hi:

I have a Frame1 and ListBox1 on UserForm1.

Also have a Picture on UserForm1.

My problem is; I can change the BackStyle prorerties to fmBackStyleTransparent of the all controls on UserForm1. And it's ok. But i can not change the same thing for Frame1 and ListBox1. :dunno

I tried the codes shown below:

ListBox1.BackColor = fmBackStyleTransparent
Frame1.BackColor = fmBackStyleTransparent
But Frame1 and ListBox1 will get black color while the codes run.:think:

So, what i have to do for resolve it? An API or something else?
I need your ideas and suggestions.

(By the way, i attaeched my file.)

Thank you very much. :friends:

Erdin? E. Ka
01-05-2007, 03:43 PM
Opps!!

The header must be :
Don't have Frame1 & ListBox1 BackStyle = fmBackStyleTransparent Property?

I wrote wrong. So sorry guys..

Ken Puls
01-05-2007, 04:36 PM
No worries, Erdinc. I've modified the post title for you. :)

Ken Puls
01-05-2007, 04:53 PM
Hmm... see what you mean. 0 (numerical equivalent) just sets it to black, not transparent.

I took a quick stroll through google, but can't see any way there either. Is the frame going to sit on a solid background? Can you sample the colour from your background image and set the back color to that?

EDIT: Only link that came up as close has no answer (yet). At least it's recent though... http://www.a1vbcode.com/a1vbcode/vbforums/Topic15442-3-1.aspx

Erdin? E. Ka
01-05-2007, 05:03 PM
No worries, Erdinc. I've modified the post title for you. :)

Thanks Ken. :yes



Hmm... see what you mean. 0 (numerical equivalent) just sets it to black, not transparent.

I took a quick stroll through google, but can't see any way there either. Is the frame going to sit on a solid background? Can you sample the colour from your background image and set the back color to that?

Hi Ken, unfortunately my background image's color is not single. The image is like a cover of a litte program and have some different types and colurs. Therefore it is not suitable for this issue.

Should i research for an API?

Erdin? E. Ka
01-06-2007, 04:34 AM
Hi again, :hi:

I found out a link for Transparent but i can't understand because is't written by French language.

http://www.vbfrance.com/codes/SUITE-FIN-TRANSPARENCE-MOBILITE-CONTROLES_24305.aspx

Also i found an add-in at Ivan F Moala's website.
http://www.xcelfiles.com/SeachSite.html

(But i could not post here because too lagre for add here: 282 KB Around...) :dunno

This add-in is very beautiful and have an API for transparent UserForm.:thumb

Can anybody help me to adaptation this API for my Frame1 and ListBox1?

Thanks in advance.:friends:

Andy Pope
01-06-2007, 07:12 AM
How about adding another image control to the frame and positioning it such that it aligns with the one on the userform.

Assuming Image1 is on the userform and Image2 is within Frame1.

Image2.Move Image1.Left - Frame1.Left, Image1.Top - Frame1.Top


You will need to play with the calculation a little to include caption and border.

Andy Pope
01-06-2007, 07:24 AM
My bad I should have checked your example workbook before posting.

The listbox will remain solid. But to be honest if it was transparent you would have a great difficulting reading it's contents.

This will do is you add a image to frame 1.

Image1.Move 0 - Frame1.Left - 3, 0 - Frame1.Top - 15

On a personal note I think the background formatting is to noisey. If you must have the image have it as a small banner at the top or bottom but away from the input controls.

tstom
01-06-2007, 08:46 AM
Erdin?,

I am assuming that you will have controls hosted within your frame? If not, setting it transparent is the same as simply making it invisible. The listbox and frame are not windowless but they are children. As far as I know, you cannot set the opacity of a child window. The only option I can concieve of for your frame would be to clip the background region within the userfrom that is overlayed by the frame, create a new bitmap from this region, and then set that bitmap to the picture property of your frame. To see what this would produce, open the attached and click on the "Toggle Frame1 picture" button to toggle the frame from the clipped background to a solid color background. Note that the gridmarks are within the frame's background picture because I clipped the area in design mode.

I have so suggestions for your listbox though I cannot imagine the need for making a listbox transparent to begin with.

Bob Phillips
01-06-2007, 12:57 PM
I found out a link for Transparent but i can't understand because is't written by French language.

http://www.vbfrance.com/codes/SUITE-FIN-TRANSPARENCE-MOBILITE-CONTROLES_24305.aspx


Erdin?,

How did you find out that this worked?

tstom
01-06-2007, 01:44 PM
You can set the opacity of a userform, but no a control. I'm pretty sure about this. Place this on a userform with ScrollBar1.


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 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 FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

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

Private Sub SetOpacity(Opacity As Byte)
Dim NewLong As Long, Hwnd As Long
Hwnd = FindWindow(vbNullString, Me.Caption)
NewLong = GetWindowLong(Hwnd, GWL_EXSTYLE)
SetWindowLong Hwnd, GWL_EXSTYLE, NewLong Or WS_EX_LAYERED
SetLayeredWindowAttributes Hwnd, 0, CInt(Opacity), LWA_ALPHA
End Sub

Private Sub ScrollBar1_Change()
SetOpacity 255 - ScrollBar1.Value
End Sub

Erdin? E. Ka
01-06-2007, 06:13 PM
Hi all,:hi:

Thank you very much for your personal note and kindly help Andy Pope, i'll keep it. :thumb

Tom, Frame1 is ok with your "Toggle Frame1 picture" button method. Thank you very much. So, it's looks like better if i don't use ListBox1 like my wish. A small banner is sound like well.:friends:

Bob, actually i didn't controlled that codes because descriptions of that codes in French language and i can't understand French language. So, i couldn't sure that codes. Maybe that is wrong or may have some error, i am not sure that.:dunno

Tom, your SetOpacity API is wonderful. Many thanks.:clap:

Thank you all again...:hi: