I've not looked at the [OnMouseWheel] event previously and was surprized how easy it was to impliment a [Zoom] facility. I had prevously set up a TTrackBar to deal with the Zoom but the idea of using the MouseWheel seemed to be more 'intuitive' for the end user.
The proc for the TTrackBar is very simple :
procedure TForm1.ZoomChange(Sender: TObject);
begin
Mag := Zoom.Position/100;
if Mag < 0.1 then
Mag := 0.1;
Calc(self);
end;
You'll see that it just checks for a minimum size.
For the MouseWheel event it's very similar :
procedure TForm1.DisplayMouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
begin
Mag := Mag*(WheelDelta/100);
if Mag < 0.1 then
Mag := 0.1;
Zoom.Position := Round(Mag*100);
Calc(self);
end;
It still checks for the Min but also sets the TTrackBar position - just to keep the two 'in sync'.
The (WheelDelta/100) was decided empirically - starting with /1 then /1000 - /100 seems OK but further tests may change that.
This works as anticipated --- but only when enlarging ie. pushing the Wheel forward -- as soon as I pull the wheel back - just one click - the Magnification becomes the Min (0.1)
Assuming that WheelDelta might become negative, I tried ABS(WheelDelta/100) but that made the 'negative' Zoom maximize. ???
I can see from the description of the TMouseWheelEvent that WheelDelta is "How many notches the wheel has been turned" but there doesn't appear to be a 'direction' parameter which I might be able to use.
Can anyone shed some light on how I might better determine the level of magnification - specifically in the negative direction?