Results 1 to 8 of 8

Thread: loose cursor on listbox

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2008
    Posts
    104

    Question loose cursor on listbox

    Hi. I used the following code to disable the cursor over the listbox (try to still have the scrolling function for the listbox but disable its clicks).

    Code:
    Private Sub List1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    
    ListBoxToolTip List1, y, "(empty)"
        If (x < 0) Or (y < 0) Or (x > List1.Width) Or (y > List1.Height) Then
           ReleaseCapture
           ShowCursor 1
        ElseIf GetCapture() <> List1.hwnd Then
           SetCapture List1.hwnd
           ShowCursor 0
           End If
           
    End Sub
    However, when I tested again today, found the listed items could be selected still and once one is selected, the cursor disapares totally, not just within the listbox. Anything wrong? Can anyone help? or any other better solutions for this??

    Thanks.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: loose cursor on listbox

    Are you trying to set it so that nothing can be selected from the ListBox?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2008
    Posts
    104

    Re: lose cursor on listbox

    Quote Originally Posted by Hack
    Are you trying to set it so that nothing can be selected from the ListBox?
    yes.

    But I don't want to use something like
    Code:
    List1.ListIndex <> -1 Then List1.ListIndex = -1
    as the mouse still can click on the listbox and the item changes color that confuse the user (because I have a few other lists on the same form). Any ideas??

  4. #4
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: loose cursor on listbox

    I have one solution, but its way different and a bit more code. Basically it puts a clear picture box over a control so the user can see it perfectly as if the control was enabled but can't select anything or use the scroll bars.

  5. #5
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: loose cursor on listbox

    I don't have VB6 with me. This work for me with Form2 ListBox in VBA: user still can use scrollbar but cannot click on list items.
    Try to see if it works with VB ListBox.
    Code:
    '-- In VB, "ByVal" may not present
    Private Sub List1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
        '-- 14 : this number is a bit smaller than the width of scrollbar that you can adjust
        List1.Locked = (X < List1.Width - 14)
    End Sub
    Last edited by anhn; Aug 4th, 2008 at 08:43 PM.
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Apr 2008
    Posts
    104

    Re: loose cursor on listbox

    Quote Originally Posted by anhn
    I don't have VB6 with me. This work for me with Form2 ListBox in VBA: user still can use scrollbar but cannot click on list items.
    Try to see if it works with VB ListBox.
    Code:
    '-- In VB, "ByVal" may not present
    Private Sub List1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
        '-- 14 : this number is a bit smaller than the width of scrollbar that you can adjust
        List1.Locked = (X < List1.Width - 14)
    End Sub
    ".locked" is not available in VB6

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Apr 2008
    Posts
    104

    Re: loose cursor on listbox

    Quote Originally Posted by Edgemeal
    I have one solution, but its way different and a bit more code. Basically it puts a clear picture box over a control so the user can see it perfectly as if the control was enabled but can't select anything or use the scroll bars.
    I tried, it's ok still seeing the listbox behind the picture box, but I need the scrallbar working. And the cursor still dispears if I hit on the listbox

  8. #8
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: loose cursor on listbox

    There's probably a lot easier way to do this if you subclassed the listbox, but heres one idea I came up without subclassing.

    The sample project places a transparent Picture box over a ListBox to act as a .Locked method, but still allows the user to scroll the list box.

    Edit: Updated code for Listbox Tabstop.


    Edit: File removed - no reply (why do I even bother?)
    Last edited by Edgemeal; Aug 21st, 2008 at 01:11 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width