How would I make a transparent list box?
Printable View
How would I make a transparent list box?
Try this:
Code:Private Const WS_EX_TRANSPARENT = &H20&
Private Const GWL_EXSTYLE = (-20)
Private Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Function MakeListTransparent(ListCtl As Object) As Boolean
On Error Resume Next
ListCtl.BackColor = ListCtl.Parent.BackColor
SetWindowLong ListCtl.hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT
MakeListTransparent = Err.LastDllError = 0
End Function
Usage
MakeListTransparent List1
If you wish to make the Scrollbars hidden, use the ShowScrollBar API function.
Code:Private Declare Function ShowScrollBar Lib "user32" _
(ByVal hwnd As Long, ByVal wBar As Long, _
ByVal bShow As Long) As Long
Private Const SB_BOTH = 3
Private Const SB_HORZ = 0
Private Const SB_VERT = 1
Private Sub List1_Scroll()
ShowScrollBar List1.hwnd, 1, False
End Sub
It doesn't seem to work. The procedure removes the border but it keeps the bg color of the form, and doesn't allow the image to shine through. I removed Resume Next from the procedure, and there are no errors, and it just isn't working.
What shhould the function be returning? It shows false
Specifically, what's going on:
Turns off border
Makes area of list not inhabited invisible
Every row containing data stays opaque
Therefore,
It seems very strange.
What version of VB are you using? Lower version, it seems to make the Listbox grey. VB6 - transparent.
im using v5 pro
Same result for me, Matthew, and I'm using VB6 Ent.
Not sure if it'll help, but attached is an example of what I'm trying to show you (look at the executable file).
I'n not sure what the exe does, but the project behaves exactly the same as the code you gave me. When I commented out the lstControl.BackColor line, the only effect was the removal of the border. Perhaps I haven't been completely clear: I have an image in the BG, which I want to show through the listbox, not just a solid color.
One way to do this, is to keep the listbox invisible and each time wen the TopIndex changes, you have to redraw a picturebox (or something that holds the background image) using the Print statement (or TextOut API). This is also fast, so I think this would work just fine.
Oops, what am I saying! I mean each time the vertical scroll bar next to the picturebox changes...