Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Delphi Language
Expertise: Beginner
Jul 14, 1999

A Simple Right Mouse Click

Question:
I am learning Delphi 4. I'm trying to create a program that can distinguish between a right and left mouse click and perform an operation based on which button has been pressed. The tutorial I'm reading uses the TMouseButton parameter inside the procedure. It looks like this:
procedure LineForm.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
But this doesn't distinguish between left and right buttons. How do I make this happen?

Answer:
Sure it does: if you read the value of TMouseButton within the method, it'll be one of the following three values: mbLeft, mbRight, or mbMiddle.

Here's some sample code that'll do the trick:

procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  case Button of
    mbLeft : ShowMessage('You pressed the left button');
    mbRight: ShowMessage('You pressed the right button');
    mbMiddle:ShowMessage('You pressed the middle button');
  end;
end;
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap