如何修复TScrollBar MouseWheel故障?

Ple*_*rds 2 delphi scroll delphi-2006

我有一个TScrollBox内部,TFrame当我使用我的鼠标滚轮时,它根本不会向上或向下滚动ScrollBox.

我试过用

TScrollBox(Sender).Perform(WM_VSCROLL,1,0); 
Run Code Online (Sandbox Code Playgroud)

FrameMouseWheelDown但它不会触发.

有任何想法吗?

Dav*_*nan 5

我的滚动框如下所示:

type
  TMyScrollBox = class(TScrollBox)
  protected
    function DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint): Boolean; override;
    procedure WndProc(var Message: TMessage); override;
  end;

function TMyScrollBox.DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint): Boolean;
begin
  Result := inherited DoMouseWheel(Shift, WheelDelta, MousePos);
  if not Result then begin
    if Shift*[ssShift..ssCtrl]=[] then begin
      VertScrollBar.Position := VertScrollBar.Position - WheelDelta;
      Result := True;
    end;
  end;
end;

procedure TMyScrollBox.WndProc(var Message: TMessage);
begin
  if Message.Msg=WM_MOUSEHWHEEL then begin
    (* For some reason using a message handler for WM_MOUSEHWHEEL doesn't work. The messages
       don't always arrive. It seems to occur when both scroll bars are active. Strangely,
       if we handle the message here, then the messages all get through. Go figure! *)
    if TWMMouseWheel(Message).Keys=0 then begin
      HorzScrollBar.Position := HorzScrollBar.Position + TWMMouseWheel(Message).WheelDelta;
      Message.Result := 0;
    end else begin
      Message.Result := 1;
    end;
  end else begin
    inherited;
  end;
end;
Run Code Online (Sandbox Code Playgroud)

  • @David:我正在评论你上面的"解释原因"评论.当你问这个人时,为什么"完全好"会突然爆发? (4认同)
  • @Ken但我不想处理CM.我要求证明为什么CM应该在这里首选.我并没有要求知道WM和CM之间的区别.你明白我的观点了吗?对不起抢购. (2认同)