如何控制StringGrid滚动条的滚动幅度?  TStringGrid=class(Grids.TStringGrid)
  private
    procedure WMHScroll(var Message:TWMVScroll); message WM_VSCROLL;
  end;
procedure   TStringGrid.WMHScroll(var   Message:   TWMVScroll);
begin
  inherited;
  //此处代码该怎么写?
end;或者说还有其他办法控制滚动条响应

解决方案 »

  1.   

    你是指用鼠标中间的滚动轮来控制StringGrid内容的滚动幅度吗?
    如果是,那么,应该由自己设定。下面是我的一段
    实际在用的程序,但不是控制StringGrid,而是通过
    控制scrollbox来控制其中的paintbox(内容也是string)
    的上下移动的。procedure TFormD.FormMouseWheel(Sender: TObject; Shift: TShiftState;
      WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
    begin
    if WheelDelta>0 then
      begin
     scrollbox1.vertscrollbar.position:=scrollbox1.vertscrollbar.position-100;
      end
    else
      begin
      scrollbox1.vertscrollbar.position:=scrollbox1.vertscrollbar.position+100;
      end
    end;
      

  2.   

    我认为,这里的关键技术是:
    要通过paintbox的容器scrollbox1的vertscrollbar来控制上下移动,
    而不是直接控制paintbox来移动。
      

  3.   

    {直接在OnMouseWheelDown和OnMouseWheelUp里面写,不行吗?}{这是控制每次向下翻6行,向上翻的,在MouseWheelUp里写}procedure TForm1.StringGrid1MouseWheelDown(Sender: TObject;
      Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);
    begin
      with TStringGrid(Sender) do begin
        if Row < RowCount-5 then Row := Row+5;
        SetFocus;
      end;
    end;
      

  4.   

    {按你的写法,也可以加上这一句(当然,这不是“科学规范”的写法}procedure TStringGrid.WMHScroll(var Message: TWMVScroll);
    begin
      inherited;
      if Row < RowCount - 5 then Row := Row + 5;
    end;