"Steve Long" <St**********@N oSpam.com> wrote in message news:ur******** ******@TK2MSFTN GP09.phx.gbl...
I hope this isn't too stupid of a question but I'm looking for a way to
change an item in a listview control when the mouse moves over it. I'd like
to change its color and underline it for a probable internet link. Is there
a way to do that? I've looked through the help and can't find anything that,
well, helps. Perhaps I'm using the wrong control.
Any help would be appreciated.
A quick 'n' dirty method using a ListView with hovering underlines on the label only.
Note how the RefreshItem routine ensures "flickering " is kept to a minimum.
Micky
Private m_pItem As ListViewItem
Private m_iMouseX As Integer
Private m_iMouseY As Integer
Private m_pFontUnderlin e As Font
Private m_pFontRegular As Font
Private Sub frmMain_Load(By Val sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
m_pItem = Nothing
m_iMouseX = -1
m_iMouseY = -1
m_pFontRegular = New Font(m_pListVie w.Font, FontStyle.Regul ar)
m_pFontUnderlin e = New Font(m_pFontReg ular, FontStyle.Under line)
m_pListView.Vie w = View.Details
With m_pListView.Col umns
..Add("Column1" , 100, HorizontalAlign ment.Left)
..Add("Column2" , 100, HorizontalAlign ment.Left)
..Add("Column3" , 100, HorizontalAlign ment.Left)
End With
With m_pListView.Ite ms.Add("Item1")
..SubItems.Add( "Sub1")
..SubItems.Add( "Sub2")
..UseItemStyleF orSubItems = False
End With
With m_pListView.Ite ms.Add("Item2")
..SubItems.Add( "Sub1")
..SubItems.Add( "Sub2")
..UseItemStyleF orSubItems = False
End With
With m_pListView.Ite ms.Add("Item3")
..SubItems.Add( "Sub1")
..SubItems.Add( "Sub2")
..UseItemStyleF orSubItems = False
End With
End Sub
Private Sub m_pListView_Mou seLeave(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles
m_pListView.Mou seLeave
m_iMouseX = -1
m_iMouseY = -1
RefreshItem()
End Sub
Private Sub m_pListView_Mou seMove(ByVal sender As System.Object, ByVal e As System.Windows. Forms.MouseEven tArgs) Handles
m_pListView.Mou seMove
m_iMouseX = e.X
m_iMouseY = e.Y
RefreshItem()
End Sub
Private Sub RefreshItem()
Dim pItem As ListViewItem = m_pListView.Get ItemAt(m_iMouse X, m_iMouseY)
If Not pItem Is m_pItem Then
m_pListView.Beg inUpdate()
If Not m_pItem Is Nothing Then
m_pItem.SubItem s.Item(0).Font = m_pFontRegular
End If
m_pItem = pItem
If Not m_pItem Is Nothing Then
m_pItem.SubItem s.Item(0).Font = m_pFontUnderlin e
End If
m_pListView.End Update()
End If
End Sub