我在richedit的onkeydown事件中使用Ctrl+Enter组合键清空,如下如示:
procedure TForm1.RichEdit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (key=13)and(ssCtrl in shift)then
self.RichEdit1.Clear;
end;
结果却发现,清空后,为两空行,光标始终在第二行的位置,我想全部清空,光标移动到最开始的位置,同时不要什么空行,该怎么做?

解决方案 »

  1.   

    procedure TForm1.RichEdit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      case Key of
        VK_RETURN:
        if ssCtrl in Shift then
        begin
          { TODO }
          TRichEdit(Sender).Clear;
        end;
      end;
    end;procedure TForm1.RichEdit1KeyPress(Sender: TObject; var Key: Char);
    begin
      if GetKeyState(VK_CONTROL) and $8000 = $8000 then
        Key := #0;
    end;