4
votes

I need to change the speed that a list box is scrolled when an item is selected (holding left mouse button down) and the mouse is moved outside of the list box. To duplicate the behavior do the following:

  1. Drop a list box on the form (+- 250 x 200 odd). Don't make it too big otherwise the scroll bar won't be visible at the bottom.
  2. Set the number of columns to 3.
  3. Add the following code to the FormCreate:

    var
      I: Integer;
    begin
      for I := 0 to 200 do
        ListBox1.Items.Add('Item '+IntToStr(I));
    end;
    
  4. Run the application and make sure that a scroll bar at the bottom is visible. Now click and hold down the left mouse button on any of the items in the list. Move the mouse and the selected item will change depending on which item is under the mouse cursor. The problem is that the list box will scroll very quickly when the mouse moves outside of the listbox which is necessary in my case to select items that are hidden. I am trying to slow down this scroll speed.

I understand that this is not the normal usage of a list box and that the behavior might not exactly fit into the standard UI guidelines. It's needed for a very specific purpose, the problem is that the scroll speed makes it very awkward for users.

I have put something together using drag and drop and a timer but that's not ideal as the "hit" area around the control is a little bit small. It would be nice if there was an out of the box way to do it.

1
I would learn the users to scroll the mouse wheel. It has a nice effect on Windows 7 :)TLama
Unfortunately the scroll wheel doesn't work in this situation.Graymatter
Am I missing something here ? I thought your aim is to get to an item which is outside the client rectangle view. That's where you can scroll by the wheel...TLama
When I stop moving the mouse, scrolling stops here. When moved again without releasing the button, it starts scrolling again. So looks like it's kind of possible to control scrolling. Anyway, you won't find anything out of the box.Sertac Akyuz
"scroll bar at the bottom" -> "at the right"?Sertac Akyuz

1 Answers

1
votes

The below is awkward at the very least. However it's the only thing I can think of. Demonstrated using an interposer, but you can use an ApplicationEvents component or subclass any other way you like.

type
  TListBox = class(stdctrls.TListBox)
  protected
    procedure WMMouseMove(var Message: TWMMouseMove); message WM_MOUSEMOVE;
  end;

procedure TListBox.WMMouseMove(var Message: TWMMouseMove);
begin
  if GetCapture = Handle then
    Sleep(250);
  inherited;
end;