5

I'm wanting to write a component that uses the mouse wheel to zoom something similar to Google earth.

I have a component using onMouseWheel and I have properties MaxZoom MinZoom and Zoom there is a better option that StretchDraw with the bitmap I'm trying to get the location of the components area in the form

What I understand I have to find each parent until I find the tCustomform and add all Component's top and components left to get the objects location to find my objects location. is there a better way

once I have the location I can zoom a Map from the mouse cursor location if the mouse is over my object and where to zoom from.

has any one seen any code please

Johan
  • 74,508
  • 24
  • 191
  • 319
lexdean
  • 151
  • 1
  • 2
  • 13
  • I don't think this can be reliably done in a component, because the mouse wheel messages don't always go to the window under the mice. From my observations wheel messages are sometimes sent only to the "form" window, sometimes only to the window under the mice, sometimes they're sent to both! My workaround to the issue was to forward messages from the Form window to the relevant child components, and in the child components I wrote some code to try avoiding duplicate activation. The trouble is, my solution requires collaboration from the form, so it's not "self contained". – Cosmin Prund Dec 07 '10 at 10:01
  • See [How to add mouse wheel support to a component descended from TGraphicControl?](http://stackoverflow.com/a/34463279/757830), and [How to direct the mouse wheel input to control under cursor instead of focused?](http://stackoverflow.com/a/34386680/757830). – NGLN Dec 25 '15 at 19:36

2 Answers2

3

If you are writing a component then you should try overriding these 2 methods in your component:

function DoMouseWheelDown( Shift :TShiftState; MousePos :TPoint ) :Boolean; override;
function DoMouseWheelUp( Shift :TShiftState; MousePos :TPoint ) :Boolean; override;

which are protected dynamic methods of TControl. They get called whenever the mouse wheel is rotated.

Steve
  • 1,769
  • 2
  • 22
  • 33
2

It depends on what kind of content you are going to zoom ; I will only Post here how to get how long the wheel has moved

on private declaration

private
{ Private declarations }
procedure FormMouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);

on create or any other starting procedure

OnMouseWheel := formMouseWheel; // depends on you 

The FormMouseWheel comes like this

procedure FormMouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
begin
// your code here 
// WheelDelta returns you - or + values (in my computer -120 and + 120 ; 
// It depends on control panel mouse wheel settings)

//   If it is a font make the font size bigger or 
// if it is a image 
 // strech := true;
//  increase width and height of the Timage
//and put them inside a scrollbox
// 
end;

I checked it using vcl form (not inside component ), If You want to zoom post us what kind of content you want to zoom

Vibeeshan Mahadeva
  • 7,147
  • 8
  • 52
  • 102