Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

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



Application Security Testing: An Integral Part of DevOps

A Simple Right Mouse Click

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?

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);
  case Button of
    mbLeft : ShowMessage('You pressed the left button');
    mbRight: ShowMessage('You pressed the right button');
    mbMiddle:ShowMessage('You pressed the middle button');
DevX Pro
Comment and Contribute






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



Thanks for your registration, follow us on our social networks to keep up-to-date