BackgroundImage in Listview

S

Sander R

Hi, All.

I have problems with a listview control. Hopefully, I am
at the right usergroup, otherwise, I apologize.

Now, I'm finishing off a project where the main interface
is a tree view an two listviews. I would really like to
complete my design with a background image on the main
listview, but I cannot get it to work. I have been
checking out some samples and tutorials, but they all
uses panels or forms, and that works great. However, they
do not work on the listview (or treeview).

Txs :)

Sander
 
H

Herfried K. Wagner [MVP]

* "Sander R said:
I have problems with a listview control. Hopefully, I am
at the right usergroup, otherwise, I apologize.

Now, I'm finishing off a project where the main interface
is a tree view an two listviews. I would really like to
complete my design with a background image on the main
listview, but I cannot get it to work. I have been

ListView:

Quick and dirty, in VB.NET:

\\\
Private Const NOERROR = &H0
Private Const S_OK = &H0
Private Const S_FALSE = &H1
Private Const LVM_FIRST = &H1000
Private Const LVM_SETBKIMAGE = (LVM_FIRST + 68)
Private Const LVM_SETTEXTBKCOLOR = (LVM_FIRST + 38)
Private Const LVBKIF_SOURCE_URL = &H2
Private Const LVBKIF_STYLE_TILE = &H10
Private Const CLR_NONE = &HFFFFFFFF

Private Structure LVBKIMAGE
Public ulFlags As Int32
Public hbm As IntPtr
Public pszImage As String
Public cchImageMax As Int32
Public xOffsetPercent As Int32
Public yOffsetPercent As Int32
End Structure

Private Declare Sub CoUninitialize Lib "OLE32.DLL" ()

Private Declare Function CoInitialize Lib "OLE32.DLL" ( _
ByVal pvReserved As Int32 _
) As Int32

Private Declare Function SendMessageLong Lib "user32" _
Alias "SendMessageA" ( _
ByVal hwnd As IntPtr, _
ByVal wMsg As Int32, _
ByVal wParam As Int32, _
ByVal lParam As Int32 _
) As Int32

Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" ( _
ByVal hwnd As IntPtr, _
ByVal wMsg As Int32, _
ByVal wParam As Int32, _
ByRef lParam As LVBKIMAGE _
) As Int32

Private Sub SetBackground()
Dim sI As String
Dim lHDC As Int32
' Set a background image:
sI = "C:\WINDOWS\Angler.bmp"
' Set the background:
Dim tLBI As LVBKIMAGE
tLBI.pszImage = sI & ControlChars.NullChar
tLBI.cchImageMax = Len(sI) + 1
tLBI.ulFlags = LVBKIF_SOURCE_URL Or LVBKIF_STYLE_TILE
SendMessage(Me.ListView1.Handle, LVM_SETBKIMAGE, 0, tLBI)
' Set the background colour of the ListView to &HFFFFFFFF (-1)
' so it will be transparent!
SendMessageLong( _
Me.ListView1.Handle, _
LVM_SETTEXTBKCOLOR, _
0, _
CLR_NONE _
)
End Sub

Private Sub Form1_Load( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) Handles MyBase.Load
Dim lR As Int32
'// required for using bitmaps
lR = CoInitialize(0)
SetBackground()
End Sub
///

There is no easy solution for the treeview control.
 
S

Sander R

Excellent :) That worked fine. Thank you very much!

I'll play around, and see if I manage to control the size
and/or the position of the image. Great if you know that
also. Again, thank you :)

Regards
Sander
 
S

Sander R

Got it working, Mr Wagner.

Just to let you know what I did:

Change Constant as below:
Private Const LVBKIF_STYLE_TILE = &H0 '&H10

Add value to items in the structure (two last lines):
Dim tLBI As LVBKIMAGE
tLBI.pszImage = sI & ControlChars.NullChar
tLBI.cchImageMax = Len(sI) + 1

tLBI.xOffsetPercent = 100 / ListView1.Width + 100
tLBI.yOffsetPercent = 100 / ListView1.Height + 100

Now the picture will position down in the right corner of
the listview.

Thanks again for all help,

-=Sander=-
 
H

Herfried K. Wagner [MVP]

* "Sander R said:
Got it working, Mr Wagner.

Just to let you know what I did:

Change Constant as below:
Private Const LVBKIF_STYLE_TILE = &H0 '&H10

Add value to items in the structure (two last lines):
Dim tLBI As LVBKIMAGE
tLBI.pszImage = sI & ControlChars.NullChar
tLBI.cchImageMax = Len(sI) + 1

tLBI.xOffsetPercent = 100 / ListView1.Width + 100
tLBI.yOffsetPercent = 100 / ListView1.Height + 100

Now the picture will position down in the right corner of
the listview.

Thanks again for all help,

Thank you for sharing the solution with us!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top