?
Solved

How do u make objects transparent?

Posted on 2003-03-01
23
Medium Priority
?
149 Views
Last Modified: 2012-08-14
I need to make an object transparent.  I need it so the person using my program can set the transparentcy of the List box.  How would I do that?
0
Comment
Question by:Gamemaster328
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 7
  • 3
  • +2
23 Comments
 
LVL 3

Expert Comment

by:DeAn
ID: 8049382
ListBox doesn't have a BackStyle property to set Transparent.  do you mean invisible?
0
 
LVL 3

Expert Comment

by:DeAn
ID: 8049393
if so, this will toggle visibility:

List1.Visible = Not List1.Visible
0
 

Expert Comment

by:WarLord
ID: 8049610
???

i would use list1.visible = false
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Gamemaster328
ID: 8049628
oh no. not that kind of transparent.  like a piece of plastic you can see through it.  that kind of transparent.
0
 
LVL 3

Expert Comment

by:DeAn
ID: 8049635
I said it toggles the visibility.

0
 

Expert Comment

by:planetULTRA
ID: 8049651
Create a new Classmodule and call it clsAlpha

Then copy&paste the following code


''''''''''''''''''''''''''''''''''''''''''


Option Explicit

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 GetWindowLong Lib "user32" _
    Alias "GetWindowLongA" _
    (ByVal hwnd As Long, _
    ByVal nIndex As Long) As Long

Private Declare Function RedrawWindow Lib "user32" _
    (ByVal hwnd As Long, _
    lprcUpdate As RECT, _
    ByVal hrgnUpdate As Long, _
    ByVal fuRedraw 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 Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type

Private Const WS_EX_LAYERED = &H80000
Private Const GWL_EXSTYLE = (-20)
Private Const LWA_ALPHA = &H2

Private Const RDW_ALLCHILDREN = &H80
Private Const RDW_ERASE = &H4
Private Const RDW_FRAME = &H400
Private Const RDW_INVALIDATE = &H1

Friend Sub SetLayered(ByVal hwnd As Long, ByVal bolSetAs As Boolean, ByVal bAlpha As Byte)
   
    Dim nullRect As RECT
    Dim lret As Long
   
    lret = GetWindowLong(hwnd, GWL_EXSTYLE)

    If bolSetAs = True Then
        lret = lret Or WS_EX_LAYERED
    Else
        lret = lret And Not WS_EX_LAYERED
    End If
   
    SetWindowLong hwnd, GWL_EXSTYLE, lret
   
    If bolSetAs Then
        SetLayeredWindowAttributes hwnd, 0, bAlpha, LWA_ALPHA
    Else
        RedrawWindow hwnd, nullRect, 0&, RDW_ALLCHILDREN Or RDW_ERASE Or RDW_FRAME Or RDW_INVALIDATE
    End If
End Sub

Friend Sub ReleaseDisplay(ByVal hwnd As Long)
    SetLayered hwnd, False, 255
End Sub


''''''''''''''''''''''''''''''''''''''''''

I think the code is easy to understand. All you need is
the handle (hwnd) of your form/control.

For example, on your form create a scrollbar.
Set its maximum to 255 and minimum to 0.

In its "Scroll" event insert the following code:

''''''''''''''''''''''''''''''''''''
   objAlpha.SetLayered listview.hwnd, True, CByte(scrollbar.Value)
   Me.Refresh
   scrollbar.Refresh
'''''''''''''''''''''''''''''''''''''

WARNING!!: This code only works under Win2K/XP
Any windows versions below Windows 2000 don't have the
SetLayeredWindowAttributes API implemented yet.
So transparency below win2k is impossible.
0
 

Author Comment

by:Gamemaster328
ID: 8049981
it doesn't work. It keeps saying there is something wrong with this one:

objAlpha.SetLayered listview.hwnd, True, CByte(scrollbar.Value)
0
 

Author Comment

by:Gamemaster328
ID: 8050675
since im new at programing this kind of thing?  what does hwnd mean?  what do i have to replace with it?
0
 

Expert Comment

by:planetULTRA
ID: 8051021
of course you have to replace the listview.hwnd
with NAMEOFYOURCONTROL.hwnd

and the scrollbar.value replace with NAMEOFYOURSCROLLBAR.value

A hwnd, or handle, is a long number that windows gives every
control. You can communicate with such controls by using
its hwnd(handle number).

Try replacing the listview.hwnd with me.hwnd. Then the
whole form should become transparent (me.hwnd gives the
handle of your form)
0
 

Author Comment

by:Gamemaster328
ID: 8052662
it still doesn't work. :-(

i did what u said but i didn't what to make the form that the scroll bar was in transparent. so i changed it.

Private Sub form4_transparent_Scroll()
    objAlpha.SetLayered Form1.hwnd, True, CByte(form4_transparent.Value)
    Me.Refresh
    form4_transparent.Refresh
End Sub

i know that there is something wrong with this so plz dont kill me!

the scrollbar's name is form4_transparent
the form that the scrollbar is in is form4
and the form im trying to make transparent is form1
0
 

Expert Comment

by:planetULTRA
ID: 8053139
AAAAH I'm so stupid! Please forgive me!

At first instead of me.refresh type form1.refresh.

Then I forgot to post some declarations:

In the form which contains the scrollbar (you can also
use a slider) paste (or type) the following code at the
beginning


''''''''''''''''''''''''''''''''''''''

Option Explicit

' Variable to hold the instance of our class
Dim objAlpha As clsAlpha

Private Sub Form_Load()
    ' Load an instance of the class object into the variable.

    Set objAlpha = New clsAlpha
End sub

'''''''''''''''''''''''''''''''''''''''

It was my fault! Please excuse me!
Now it should work
0
 

Author Comment

by:Gamemaster328
ID: 8053217
oh ok that you let me see if it works
0
 

Author Comment

by:Gamemaster328
ID: 8053233
now its saying that there is something wrong with this code:

Dim objAlpha As clsAlpha

(the objAlpha As clsAlpha is wrong it says.)
0
 

Expert Comment

by:planetULTRA
ID: 8053329
Then you forgot to call the classmodule clsAlpha
0
 

Author Comment

by:Gamemaster328
ID: 8053438
o ok
let me see if it works this time
0
 

Author Comment

by:Gamemaster328
ID: 8053446
still not working

    objAlpha.SetLayered clsAlpha.hwnd, True, CByte(form4_transparent.Value)
    Form1.Refresh
    Me.Refresh
0
 

Author Comment

by:Gamemaster328
ID: 8053463
runtime error 404

object required
0
 

Accepted Solution

by:
planetULTRA earned 75 total points
ID: 8053539
0
 

Expert Comment

by:planetULTRA
ID: 8053544
Are you sure you have at least Windows 2000?
0
 

Author Comment

by:Gamemaster328
ID: 8053933
yes
0
 

Author Comment

by:Gamemaster328
ID: 8055025
IT WORKS!!!!  thanks.  i dont know who to give the points to though.

if i could i would like to split it up but i cant. (i dont want to add more)

how should i settle this?

i guess im gonna have to give it to planetUltra.
0
 

Expert Comment

by:planetULTRA
ID: 8064539
I'm glad that I could help you!
0
 

Expert Comment

by:bzz
ID: 9169909
planetUltra: I spent a couple of hours finding a solution for making a single control transparent, and came across this proposed solution. It does not appear to work, and from what I've seen on similar topics it will not. As far as I can tell, Visual Basic only supports transparency for an entire window, not for individual controls.

I would gladly be proven wrong, since the solution I'm using now is more elaborate.

PS: The link to the example is not valid.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month13 days, 4 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question