首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >拖动和MouseDown冲突

拖动和MouseDown冲突
EN

Stack Overflow用户
提问于 2013-06-26 10:24:51
回答 1查看 753关注 0票数 0

我有一个将DragMode设置为dmAutomatic的列表框,用于将项目的文本拖到其他地方。

我将多选设置为true。我希望能够在我的列表框项目上单击并拖动,以按顺序选择多行。所以我有:

代码语言:javascript
复制
Shift := [ssLeft];

ListBoxMouseDown事件中。多选拖动不起作用。如果我在按住shift键的同时单击并拖动,则会获得所需的结果。对于为什么或者如何解决这个问题,有什么建议吗?

EN

回答 1

Stack Overflow用户

发布于 2013-06-26 10:50:29

你做错了这件事。根本不要使用DragMode=dmAutomatic,它不适合您尝试使用它的方式。相反,在OnMouseDown事件中,当左键按下时设置一个标志。在OnMouseMove事件中,如果设置了标志,请选择鼠标下的当前项。在OnMouseUp事件中,清除该标志。例如:

代码语言:javascript
复制
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;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17310566

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档