Solved

-- On Right-Click Mouse event

Posted on 1998-10-20
20
197 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now