Delphi在滚动时阻止TRect移动

时间:2013-10-02 09:08:51

标签: delphi delphi-xe3

我有一个Listview,其中我添加了TRect一个TEdit框并将其连接到一个单元格。一切正常但是当我调整窗口大小以使滚动条可见并更改滚动值时,编辑框不会锁定到单元格。 TRect(TEdit框)随着滚动值移动并离开我希望它留在的字段。

任何建议?

以下是OnMouseDown事件。

var
  pt: TPoint;
  ListItem: TListItem;
  lvHitInfo: TLVHitTestInfo;
  Ind: Integer;
  LVRect: TRect;
  ScrollOffsetHoriz: Integer;
  DeleteObject: TDeleteObject;
begin
  SendMessage(Handle, WM_SETREDRAW, WPARAM(False), 0);
  try
    pt := ListView.ScreenToClient(Mouse.CursorPos);

    ScrollOffsetHoriz := ListView.Items[0].DisplayRect(drBounds).Left;
    ListItem := ListView.GetItemAt(pt.X, pt.Y);
    FDeleteRow := -1;
    // over a sub item?
    if Assigned(ListItem) then
    begin
      FillChar(lvHitInfo, SizeOf(lvHitInfo), 0);
      lvHitInfo.pt := pt;
      if ListView.Perform(LVM_SUBITEMHITTEST, 0, LParam(@lvHitInfo)) <> -1 then
      begin
        LVRect.Left := ScrollOffsetHoriz;
        for Ind := 0 to lvHitInfo.iSubItem - 1 do
          LVRect.Left := LVRect.Left + ListView.Columns[Ind].Width;
        LVRect.Right := LVRect.Left + ListView.Columns[lvHitInfo.iSubItem].Width;
        LVRect.Top := ListItem.DisplayRect(drBounds).Top;
        LVRect.Bottom := ListItem.DisplayRect(drBounds).Bottom;

        FSelectedSubIndex := lvHitInfo.iSubItem;
        FSelectedIndex := lvHitInfo.iItem;
      end;

0 个答案:

没有答案