Automatically allowing Ctrl+A to select all in a TMemo?

后端 未结 2 711
谎友^
谎友^ 2021-02-07 23:43

In Delphi 7\'s TMemo control, an attempt to do the key combo Ctrl + A to select all does not do anything (doesn\'t select all). So I\'ve made this procedure:

<
相关标签:
2条回答
  • 2021-02-07 23:54

    I used the previous answer and discussion to create a standalone component which handles the KeyPress event which I use in small test programs.

    TSelectMemo = class(TMemo)
    protected
      procedure KeyPress(var Key: Char); override;
    end;
    

    ...

    procedure TSelectMemo.KeyPress(var Key: Char);
    begin
      inherited;
      if Key = ^A then
        SelectAll;
    end;
    

    Another way of adding "select all" behavior to all components on a form is to add an action list to your form with a standard select all action.

    0 讨论(0)
  • 2021-02-07 23:55

    This is more elegant:

    procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
    begin
      if Key = ^A then
      begin
        (Sender as TMemo).SelectAll;
        Key := #0;
      end;
    end;
    
    0 讨论(0)
提交回复
热议问题