单击最后一项时如何禁用CheckListBox滚动?

时间:2019-04-24 11:13:10

标签: delphi vcl delphi-xe7 delphi-10.2-tokyo checklistbox

如果CheckListBox中有足够的项目,则它具有一个滚动条,每当单击最后一个项目时,它就会滚动到下一个项目,这将导致异常行为:

  • 选中/取消选中下一项,而不是我单击的

在Delphi XE7和更高版本的10.2 Tokyo中进行了测试,并且具有相同的作用

试图捕获WM_LBUTTONDOWN消息并对其进行跟踪,从而找到发生事件的确切位置。

Vcl.Controls.pas

...
procedure TControl.WMLButtonDown(var Message: TWMLButtonDown);
begin
  SendCancelMode(Self);

  inherited; //there it scrolls by 1 line

  if csCaptureMouse in ControlStyle then
    MouseCapture := True;
  if csClickEvents in ControlStyle then
    Include(FControlState, csClicked);

  DoMouseDown(Message, mbLeft, []); // it does the check/uncheck
end;
...

用于复制的代码:(并在表单上放置一个TCheckListBox)

...

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
begin
  CheckListBox1.Height := 145; //just so it's short enough
  for i := 0 to 30 do
  begin
CheckListBox1.Items.Add('Item'+IntToStr(i));
  end;
end;
...

然后单击底部显示的项目的复选框。

还尝试通过该单元,该单元包含有关CheckListBox的所有内容(Vcl.CheckLst,但未找到任何可用的

编辑

BrakNicku发现他只能复制部分物品,这对我来说也是如此

他的解决方案:将IntegralHeight属性设置为True,以防止出现此问题。

0 个答案:

没有答案