1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
TFileListBox = class(Filectrl.TFileListBox)
function DoMouseWheel(_Shift: TShiftState; _WheelDelta: Integer; _MousePos: TPoint): Boolean; override;
protected
procedure WMVScroll(var Msg: TWMVScroll); message WM_VSCROLL;
end;
TForm1 = class(TForm)
...
implementation
uses Math;
{ TFileListBox }
function TFileListBox.DoMouseWheel(_Shift: TShiftState; _WheelDelta: Integer; _MousePos: TPoint): Boolean;
var
Idx: Integer;
begin
// calculer l'index de l'élément à sélectionner
Idx := ItemIndex - Sign(_WheelDelta);
if Idx >= Items.Count then
Idx := Items.Count
else if Idx < 0 then
Idx := 0;
// sélectionnez-le
ItemIndex := Idx;
// et simuler un clic de souris dessus pour que le tableau sélectionné s'affiche
Self.Click;
Result := True;
end;
procedure TFileListBox.WMVScroll(var Msg: TWMVScroll);
begin
case Msg.ScrollCode of
SB_LINEUP: if ItemIndex - 1 >= 0 then
ItemIndex := ItemIndex - 1;
SB_LINEDOWN: if ItemIndex + 1 < Count then
ItemIndex := ItemIndex + 1;
else
inherited;
end;
end; |
Partager