我有一个将DragMode设置为dmAutomatic的列表框,用于将项目的文本拖到其他地方。
我将多选设置为true。我希望能够在我的列表框项目上单击并拖动,以按顺序选择多行。所以我有:
Shift := [ssLeft];在ListBoxMouseDown事件中。多选拖动不起作用。如果我在按住shift键的同时单击并拖动,则会获得所需的结果。对于为什么或者如何解决这个问题,有什么建议吗?
发布于 2013-06-26 10:50:29
你做错了这件事。根本不要使用DragMode=dmAutomatic,它不适合您尝试使用它的方式。相反,在OnMouseDown事件中,当左键按下时设置一个标志。在OnMouseMove事件中,如果设置了标志,请选择鼠标下的当前项。在OnMouseUp事件中,清除该标志。例如:
var
Dragging: Boolean = False;
procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
If Button = mbLeft then
Dragging := True;
end;
procedure TForm1.ListBox1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
If Button = mbLeft then
Dragging := False;
end;
procedure TForm1.ListBox1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
Index: Integer;
begin
If not Dragging then Exit;
Index := ListBox1.ItemAtPos(Point(X, Y), True): Integer;
If Index <> -1 then
ListBox1.Selected[Index] := True;
end;https://stackoverflow.com/questions/17310566
复制相似问题