Link to home
Start Free TrialLog in
Avatar of jl2001
jl2001

asked on

How to write some codes for Right Clicking mouse?

Hi, experts:

Can anyone solve the problem?

I must use mousedown to allocate clicking position(leftclick) on a label. How can I use mouse rightclick on the label to show a message?

thanks a lot!

John
Avatar of sundayboys
sundayboys

Use OnContextPopup event.like this:
procedure TForm1.Label1ContextPopup(Sender: TObject; MousePos: TPoint;
  var Handled: Boolean);
begin
   showmessage('ok');
end;
ASKER CERTIFIED SOLUTION
Avatar of Member_2_248744
Member_2_248744
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
var
  clickpos:TPoint;

procedure TForm.Label1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y:integer);
const
  RADIUS = 4;
begin
  if Button = mbRight then
  begin
    clickpos.X := X;
    clickpos.Y := Y;
    ShowMessage('The new click position is X:' + IntToStr(X) + ' Y:' + IntToStr(Y));
  end
  else if Button = mbLeft then
  begin
    if (X >= clickpos.X - RADIUS) and (X <= clickpos.X + RADIUS) and (Y >= clickpos.Y - RADIUS) and (Y <= clickpos.Y + RADIUS) then
      ShowMessage('CLICKED !!');
  end;
end;
Avatar of jl2001

ASKER

simple, straight forward and no bugs
Avatar of jl2001

ASKER

Thanks a lot, guys.