Solved

-- On Right-Click Mouse event

Posted on 1998-10-20
20
204 Views
Last Modified: 2010-04-06
Hey there !

Everything ( almost ) has its "Onclick" event..
but... what about "On right click " ?
( I mean, mouse right click )

bryan
0
Comment
Question by:bryan7
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 7
  • 2
  • +1
20 Comments
 
LVL 4

Expert Comment

by:BoRiS
ID: 1343506
bryan7

For a onright click event you will need to create your own...although there are a few components that have one already...

do you need it for a component you written or just in your code...

Later
BoRiS
0
 
LVL 1

Expert Comment

by:jecksom
ID: 1343507
Hi , bryan7!

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
{(mbLeft, mbRight, mbMiddle}
if button=mbRight then
showmessage('I''ve catched right mouse click on form1');
end;

you could do OnMouseDown event for most componnents ... or i
didn't got your question .

Jecksom

0
 
LVL 3

Author Comment

by:bryan7
ID: 1343508
yeah ! thanx !

it works.

Boris: If I wanted to add it in my own components, how would it be ?
I still don't know how to make a new component..

thanx ya all.

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:viktornet
ID: 1343509
Hello bryan~

for a new component it would be like this....

TRightButton = class(whatever)
public
  procedure RightClick(var Message : TMessage);
    message WM_RBUTTONDOWN;
{...}
procedure TRightButton.RightClick(var Message : TMessage);
begin
  Inherited;
  ShowMessage(' The right button was just pressed :-) ');
end;

Hope this helps~

If you need more help just ask

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1343510
Oh...you need to have an OnRightClick() event,,,right??? Ok here is how you do that :-)

   TRightButton = class(whatever)
    private
      FOnRightClick : TNotifyEvent;
   public
     procedure RightClick(var Message : TMessage);
       message WM_RBUTTONDOWN;
   published
     property OnRightClick : TNotifyEvent read FOnRightClick write FOnRightClick;
   {...}
   procedure TRightButton.RightClick(var Message : TMessage);
   begin
     Inherited;
     if Assigned(FOnRightClick) then FOnRightClick(self);
   end;

Hope this helps :-)

Regards,
Viktor Ivanov
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1343511
bryan7

just as viktornet said...

Later
BoRiS
0
 
LVL 3

Author Comment

by:bryan7
ID: 1343512
I tried to mix it with a component which I had the source from,
but had no success.

bryan
Notes: I'm using Delphi3.


0
 
LVL 3

Author Comment

by:bryan7
ID: 1343513
Is there the source code of all the components on the palette ?

bryan

0
 
LVL 3

Author Comment

by:bryan7
ID: 1343514
Ok, I use

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
        Shift: TShiftState; X, Y: Integer);
      begin
      {(mbLeft, mbRight, mbMiddle}
      if button=mbRight then
      showmessage('I''ve catched right mouse click on form1');
end;

and it works perfectly, now.. how to handle with OnRightdoubleClick ?

I'll increase the points if you want.

bryan

0
 
LVL 10

Accepted Solution

by:
viktornet earned 0 total points
ID: 1343515
I didn't test the code I posted above, but now as I tried that code it works perfectly... Here is what I got...I've descended this component

//------------------------------- TRightButton Unit  ------------------------------//
unit RightButton;
interface
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;
type
  TRightButton = class(TButton)
  private
    FOnRightClick : TNotifyEvent;
  protected
    { Protected declarations }
  public
    procedure RightClick(var Message : TMessage);message WM_RBUTTONDOWN;
  published
    property OnRightClick : TNotifyEvent read FOnRightClick write FOnRightClick;
  end;
procedure Register;
implementation
procedure TRightButton.RightClick(var Message : TMessage);
begin
  Inherited;
  if Assigned(FOnRightClick) then FOnRightClick(self);
end;
procedure Register;
begin
  RegisterComponents('Samples', [TRightButton]);
end;
end.
//----------------- End of TRightButton Unit -----------------------//
//----------------- Start of Sample Code --------------------------//
unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, RightButton;
type
  TForm1 = class(TForm)
    RightButton1: TRightButton;
    procedure RightButton1RightClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.RightButton1RightClick(Sender: TObject);
begin
  ShowMessage('Hello World!');
end;
end.
//--------------------- End of Sample Code Unit ----------------//

The sample code works exactly as expected... I''ve placed my new component on the for and in its OnRightClick() have entered to show a message... Hope this helps  now.///

Regards,
Viktor Ivanov
0
 
LVL 3

Author Comment

by:bryan7
ID: 1343516
hey, great ! viktornet.

I tried the same with a Panel and it works. I'll try to learn a bit, about
 making components.

Now, the last question, to close this one, how to handle with  
 
         OnRightDoubleClick     ?

( if it's possible )

I'll increase the points if you want, just tell me,

bryan

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1343517
Hello Bryan!
>I tried the same with a Panel and it works. I'll try to learn a bit, about
>making components.
If you need any help with writing components just tell me and I'll help you learn how to do that...
>Now, the last question, to close this one, how to handle with  
>OnRightDoubleClick     ?
Don;t understand your question... What do you mean by handle with the OnRightDoubleClick??
>I'll increase the points if you want, just tell me,
No need to increase the points.

Please clarify your question.. Thanks...

Cheers,
Viktor
0
 
LVL 3

Author Comment

by:bryan7
ID: 1343518
Hey there,
 
I  mean, all the components have the OnDoubleClick event.
How can I know if the user "DoubleClicks" with the right mouse button ?


thanx, bryan

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1343519
Hello Bryan!

That might be possible but I don't know a way of doing that... The thing is that there is only a WM_LBUTTONDBLCLICK and there isn't for the right button... I don't know if it's possible... There is a way which is not a good one at all... You can have a timer and do that, but as I mentioned it's not a good way of programming...

Cheers,
Viktor
0
 
LVL 3

Author Comment

by:bryan7
ID: 1343520
Yeah, I know, enabling a timer when the user Right clicks, then set to TRUE a variable
when the user releases the button, and after 1/10 seconds, or something like that,
with the OnTimer event, check if the variable is set at TRUE, and if so, then the user
used the right button,

But I'd like to avoid doing that if possible.

thanx.( I'll wait 2 more days to see if someone drops any other comment )

bryan
0
 
LVL 3

Author Comment

by:bryan7
ID: 1343521
sorry, I meant set to 1 a variable when releasing the button, then set it to 2 on the second
click.

bryan

0
 
LVL 3

Author Comment

by:bryan7
ID: 1343522
viktor: now I know how to do it..

in the form OnMouseDown event:

if button=mbRight then =======  ( button= right )
if ssdouble in shift then ======  ( right button double click ! )

bryan


0
 
LVL 10

Expert Comment

by:viktornet
ID: 1343523
good for you
0
 
LVL 3

Author Comment

by:bryan7
ID: 1343524
well,, i droped this for you, since you said you didn't know it..

bryan
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1343525
well, i didn;t know it and don't need it but anyway, 10x :o)

Cheers,
Viktor
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question