Delphi禁用鼠标按钮并再次启用

时间:2014-06-20 17:40:59

标签: delphi click mouse

我需要在TRichEdit组件的事件OnMouseEnter上禁用两个鼠标按钮,并在事件OnMouseLeave上再次启用。

设置TRichEdit enabled = false并不能解决我的问题。

任何提示?

1 个答案:

答案 0 :(得分:4)

您可以对富编辑进行子类化,以拦截鼠标按钮向下/向上消息。然后你不需要注意鼠标进入,离开控件。例如:

type
  TForm1 = class(TForm)
    ...
  private
    FSaveRichEditProc: TWndMethod;
    procedure RichEditWindowProc(var Message: TMessage);
    ..
  end;

  ...

procedure TForm1.FormCreate(Sender: TObject);
begin
  FSaveRichEditProc := RichEdit1.WindowProc;
  RichEdit1.WindowProc := RichEditWindowProc;
end;

procedure TForm1.RichEditWindowProc(var Message: TMessage);
begin
  case Message.Msg of
    WM_LBUTTONDOWN, WM_LBUTTONUP, WM_LBUTTONDBLCLK,
    WM_MBUTTONDOWN, WM_MBUTTONUP, WM_MBUTTONDBLCLK,
    WM_RBUTTONDOWN, WM_RBUTTONUP, WM_RBUTTONDBLCLK:
      begin
        Message.Result := 0;
        Exit;
      end;
  end;
  FSaveRichEditProc(Message);
end;