Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I disable onmousemove when onmousedown is used? 2

Status
Not open for further replies.

pierrotsc

Programmer
Nov 25, 2007
358
US
I am doing a paint program and when i press the mouse to draw I would like to disable the onmousemove event. Is that possible?
Thanks.
PO
 
You can disable an event by setting the handler to nil. Later you can restore the event by setting the handler to the proper procedure.

Code:
procedure TForm1.DisableMouseMove;
begin
  Memo.OnMouseMove := nil;
end;

procedure TForm1.EnableMouseMove;
begin
  Memo.OnMouseMove := MemoMouseMove;
end;

procedure TForm1.MemoMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  DisableMouseMove;
end;

procedure TForm1.MemoMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  EnableMouseMove;
end;

procedure TForm1.MemoMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  Self.Caption := inttostr(x) + ':' + inttostr(y);
end;
 
I presume you are just drawing straight lines from <mouse down> to <mouse up>?

It is easily possible.
Code:
procedure Form1.FormMouseDown( ... );
  begin
  Form1.OnMouseMove := nil;
  ...
  end;

procedure Form1.FormMouseUp( ... );
  begin
  ...
  Form1.OnMouseMove := Form1.FormMouseMove
  end;

The other option would be to just have a private flag that indicates whether or not you want to ignore mouse move events:
Code:
procedure Form1.FormMouseMove( ... );
  begin
  if F_Is_Ignore_MouseMove then Exit;
  ...
  end;
Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top