Reputation: 6587
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:
Add the following code to the FormCreate:
var
I: Integer;
begin
for I := 0 to 200 do
ListBox1.Items.Add('Item '+IntToStr(I));
end;
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.
Upvotes: 4
Views: 1287
Reputation: 54832
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;
Upvotes: 1