• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 209
  • Last Modified:

-- On Right-Click Mouse event

Hey there !

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

bryan
0
bryan7
Asked:
bryan7
  • 10
  • 7
  • 2
  • +1
1 Solution
 
BoRiSCommented:
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
 
jecksomCommented:
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
 
bryan7Author Commented:
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
2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

 
viktornetCommented:
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
 
viktornetCommented:
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
 
BoRiSCommented:
bryan7

just as viktornet said...

Later
BoRiS
0
 
bryan7Author Commented:
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
 
bryan7Author Commented:
Is there the source code of all the components on the palette ?

bryan

0
 
bryan7Author Commented:
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
 
viktornetCommented:
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
 
bryan7Author Commented:
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
 
viktornetCommented:
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
 
bryan7Author Commented:
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
 
viktornetCommented:
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
 
bryan7Author Commented:
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
 
bryan7Author Commented:
sorry, I meant set to 1 a variable when releasing the button, then set it to 2 on the second
click.

bryan

0
 
bryan7Author Commented:
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
 
viktornetCommented:
good for you
0
 
bryan7Author Commented:
well,, i droped this for you, since you said you didn't know it..

bryan
0
 
viktornetCommented:
well, i didn;t know it and don't need it but anyway, 10x :o)

Cheers,
Viktor
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 10
  • 7
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now