我在程序中用了scrollbox,想实现鼠标滚轮的事件,通过该事件,我就可以让我得窗体上下移动。我的函数是这样的。但是不执行,请大家帮我看看!
procedure TForm2.ScrollBox1MouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
begin
scrollbox1.VertScrollBar.Position:=wheeldelta+
scrollbox1.VertScrollBar.Position;
end;

解决方案 »

  1.   

    procedure TForm1.FormMouseWheel(Sender: TObject; Shift: TShiftState;
      WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
    var
      BoxPos, ABoxPos: TPoint;
    begin
      with Scrollbox1 do
      begin
        BoxPos := ClientToScreen(Point(0, 0));
        ABoxPos := BoxPos;
        Inc(ABoxPos.X, Width);
        Inc(ABoxPos.Y, Height);
        if (MousePos.X >= BoxPos.X) and (MousePos.X <= ABoxPos.X) and
           (MousePos.Y >= BoxPos.Y) and (MousePos.Y <= ABoxPos.Y) then
        begin
          WheelDelta := WheelDelta*VertScrollBar.Range  div Self.VertScrollBar.Range;
          VertScrollBar.Position := WheelDelta + VertScrollBar.Position;
        end;
      end;
    end;————————————————————————————————————
    宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
    ————————————————————————————————————
      

  2.   


       我的scrollbox是充满整个窗体的。我试了你的方法,还是不行
    有没有其他更好一点的例子呢?