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
Solved

-- On Right-Click Mouse event

Posted on 1998-10-20
20
202 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
  • 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi component that can load a DLL in design time? 8 74
add combobox item based on numbers 9 154
Working with hours 3 65
enhance the following code 3 37
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

829 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