0

I have Two listboxes and both with Multiselect:=True. I have a popup menu that Copy/Paste to/from the Clipboard for the selected items. All works as intended.

I wanted to add keyboard CtrlC (Copy) and Ctrl+V (Paste) but after selecting items, then using Ctrl-C, the Selected items all lose selection and the first item in the list is selected and it gets copied to the Clipboard.

I am using the KeyPreview and main form OnKeyUp

if (ssCtrl in Shift) then
begin
  case Char(Key) of
   'c','C' : puCopyClick(Sender);
   'v','V' : puPasteClick(Sender);
  end;
  Exit;
end;
case Key of
  VK_Delete : puDeleteClick(Self);
end;
Exit;

How can I make the Ctrl+C etc work as the popup does?

Thanks

4

1 回答 1

2

处理快捷键的最好方法是让菜单项来处理它们。您说您有一个包含这些操作的弹出菜单。使用菜单项的Shortcut属性将该菜单项与快捷键相关联。

这允许您删除所有手动键盘事件处理并让框架为您完成。这有很多好处。其中最重要的一点是,当键按下而不是当它像您当前拥有的那样上升时,事件将触发。

如果我没记错的话,最好使用 Delphi 5 中确实存在的动作。这些允许您关联单个动作,例如复制到具有多个独立 UI 元素的剪贴板。例如,该动作可以与主菜单、弹出菜单和快捷键相关联。

于 2013-06-30T19:13:00.513 回答