Solved

VB.net Transparent ListView

Posted on 2010-08-24
9
2,693 Views
Last Modified: 2012-05-10
Hi All,

VS2008

I'm using the transparent listview code from here (http://www.vbforums.com/showthread.php?t=597891) (unmodified)
and am adding the TLV to a TabControl that has a background image (which is why i want to use the transparency)

I'm having two problems with it.

1) when it is populated the background is black, not transparent.  setting the .BackColor = Color.Transparent gives an error that it is not supported. (Changing the .BackColor to anything else doesn't change it from black)

2) I changed the .HighlightColor to Color.Tomato (the same happens for all other colors as well), and the rows stay highlighted, but the text becomes garbled after you click on the 2nd or third row (or scroll).

#1 is the more important one for now

Any suggestions?
Private WithEvents NewsList as TransparentListView



Public Sub New()

        InitializeComponent()

        NewsList = New TransparentListView

        With NewsList

            .Size = New Size(801, 219)

            .Location = New Point(100, 169)

            .View = View.Details

            .MultiSelect = False

            .FullRowSelect = True

            .ContextMenuStrip = NewsContext

            .BackColor = Color.Blue

            .HighlightColor = Color.Tomato

        End With

        OverviewTab.Controls.Add(NewsList)



End Sub

Open in new window

0
Comment
Question by:sgaggerj
  • 5
  • 4
9 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 33520326
If you really want my suggestion, then I would say that you don't have something that is designed well, and you might want to think about a different approach.  I don't see enough detail about how to use the control, and the internal refresh timer doesn't sound like a very good idea.
0
 
LVL 1

Author Comment

by:sgaggerj
ID: 33520950
yea I think I was wowed by the demo image as that's essentially the effect i wanted.

any suggestions on where to look for pre-built code (i've been googling like crazy), or where/how to start?  

What would you do to implement this feature?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 33523084
Can you attach a .png screen shot of what you are trying to achieve, and how it is working.  There might be an easier way to achieve the effect that you need, but I am not quite sure how it is working now...
0
 
LVL 1

Author Comment

by:sgaggerj
ID: 33542636
This project is a side project at the moment.  It's a PC app for games that are played on the iPhone.  Though it seems like the company has shut down their servers so this may be moot for this project, but i'd still like to do it.

unfortunately, because their servers are offline my app is no longer functional so i can't give a screenshot of what i was doing at the moment.
i'll describe it as best i can.

i have a tab page that has a background image stretched to fill the entire tab page.
i have a listview control that is about 1/3 of the area of the tab page.

i want the listview to be transparent so that the background image is obscured ONLY by the text contained in the listview.

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 33623678
I have been on vacation for a while, and I just noticed that I hadn't gotten back to this question.  I came up with something that might work, but I don't have access to that code now.  I will need to show you what I have, and see if it meets your requirements.  
0
 
LVL 1

Author Comment

by:sgaggerj
ID: 33694461
i'd love to take a look at it.  thanks!

(sorry for the late reply, i've been plugging away at my primary project)
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 33705331
Here is the code (and screen shot):


Imports System.Runtime.InteropServices

Imports System.Windows.Forms



Namespace CodeSnippets



    Public Class TransparentListView

        Inherits ListView



        Public Sub New()

            Me.OwnerDraw = True

            Me.DoubleBuffered = True

        End Sub



        Protected Overrides Sub OnDrawItem(ByVal e As DrawListViewItemEventArgs)

            TextRenderer.DrawText(e.Graphics, e.Item.Text, e.Item.Font, Me.UpdateBounds(e.Item, e.Bounds, True), Color.Red, 0)

        End Sub



        Protected Overrides Sub CreateHandle()

            MyBase.CreateHandle()



            UnsafeNativeMethods.SendMessage(Me.Handle, UnsafeNativeMethods.LVM_SETBKCOLOR, 0, UnsafeNativeMethods.CLR_NONE)

        End Sub



        Private Overloads Function UpdateBounds(ByVal item As ListViewItem, ByVal originalBounds As Rectangle, ByVal drawText As Boolean) As Rectangle

            Dim rectangle As Rectangle = originalBounds

            If (item.ListView.View = View.Details) Then

                If (Not item.ListView.FullRowSelect AndAlso (item.SubItems.Count > 0)) Then

                    Dim subItem As ListViewItem.ListViewSubItem = item.SubItems(0)

                    Dim size As Size = TextRenderer.MeasureText(subItem.Text, subItem.Font)

                    rectangle = New Rectangle(originalBounds.X, originalBounds.Y, size.Width, size.Height)

                    rectangle.X = (rectangle.X + 4)

                    rectangle.Width += 1

                Else

                    rectangle.X = (rectangle.X + 4)

                    rectangle.Width = (rectangle.Width - 4)

                End If

                If drawText Then

                    rectangle.X -= 1

                End If

            End If

            Return rectangle

        End Function



        Private Class UnsafeNativeMethods

            Friend Const CLR_NONE As Integer = -1

            Friend Const LVM_FIRST As Integer = &H1000

            Friend Const LVM_SETBKCOLOR As Integer = LVM_FIRST + 1



            <DllImport("user32.dll", CharSet:=CharSet.Auto)> _

            Friend Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As IntPtr

            End Function

        End Class



    End Class



End Namespace

Open in new window

Screenshot.png
0
 
LVL 1

Author Comment

by:sgaggerj
ID: 33716123
Narf!

Thanks - i'll take a look and give it a whirl as soon as i can,  looks like it is exactly what i was trying to do.
0
 
LVL 1

Author Closing Comment

by:sgaggerj
ID: 33830576
Works great! Thanks!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

932 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now