在RichEdit控件中使用ctrl+enter快捷键的问题

xymao123 2008-08-26 11:05:07
我想在RichEdit控件中使用ctrl+enter快捷键,但当按下组合键ctrl+enter时,
回车键起作用了,每按一次组合键,就会插入一个换行.按组合键的时候,也不会
出发OnKeyPress事件,不能通过key:=#0来屏蔽回车键.要怎么做才能实现在按
组合键ctrl+enter时,richedit不接受enter键产生的换行?

procedure TForm1.RichEdit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin

if (key=vk_return) and (ssCtrl in shift) then
begin
showmessage('KeyDown');
end;

end;

procedure TForm1.RichEdit1KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
begin
showmessage('KeyPress');
end;
end;
...全文
105 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
xymao123 2008-08-26
找到了
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;

type
TForm1 = class(TForm)
RichEdit1: TRichEdit;
Button1: TButton;
procedure RichEdit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure RichEdit1KeyPress(Sender: TObject; var Key: Char);
procedure hotykey(var msg:TMessage); message WM_HOTKEY;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
HotKey:Integer;

implementation

{$R *.dfm}

procedure TForm1.RichEdit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin

if (key=vk_return) and (ssCtrl in shift) then
begin
showmessage('KeyDown');
end;

end;

procedure TForm1.RichEdit1KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
begin
//showmessage('KeyPress');
end;
end;

procedure TForm1.hotykey(var msg:TMessage);
begin
if (msg.LParamLo=MOD_CONTROL) and (msg.LParamHi=13) then
begin
ShowMessage('你按了ctrl+enter');
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
HotKey:=GlobalAddAtom('HotKey');
RegisterHotKey(handle,HotKey,mod_control,13);

end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
UnRegisterHotKey(handle,HotKey);
end;

end.
回复
手指风 2008-08-26
估计你要用hotkey或hook来处理了
回复
xymao123 2008-08-26
//这样处理好像更简单一些
procedure TForm1.RichEdit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (key=vk_return) and (ssCtrl in shift) then
begin
self.RichEdit1.ReadOnly:=true;
showmessage(self.RichEdit1.Text);
end;
self.RichEdit1.ReadOnly:=false;
end;
回复
发帖
非技术区
创建于2007-08-02

799

社区成员

Delphi 非技术区
申请成为版主
帖子事件
创建了帖子
2008-08-26 11:05
社区公告
暂无公告