TScrollBox響應鼠標滾輪問題


Delphi的TScrollBox本身並不響應鼠標滾輪事件(不知道為什么),但可以在ScrollBox的鼠標滾動事件中進行控制:

procedure TfrmTaskNoteEdit.ScrollBox1MouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer;
  MousePos: TPoint; var Handled: Boolean);
begin
  if   WheelDelta   <   0   then
    SendMessage(scrollBox1.Handle,WM_VSCROLL,   SB_LINEDOWN,   0) //向下滾
  else
    SendMessage(scrollBox1.Handle,WM_VSCROLL,   SB_LINEUP,   0); //向上滾
end;


測試通過,奇怪的是我在一個PageControl的兩個頁面中分別放置兩個ScrollBox時只有一個有響應,郁悶,后來只好調整到窗體的MouseWheel事件中:

procedure TfrmTaskNoteEdit.FormMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint;
  var Handled: Boolean);
begin
  inherited;
  case RzPageControl1.ActivePageIndex of
    0:
    begin
      if WheelDelta < 0 then
        ScrollBox1.Perform(WM_VSCROLL,SB_LINEDOWN,0)
      else
        ScrollBox1.Perform(WM_VSCROLL,SB_LINEUP,0);
    end;
    2:
    begin
      if WheelDelta < 0 then
        ScrollBox2.Perform(WM_VSCROLL,SB_LINEDOWN,0)
      else
        ScrollBox2.Perform(WM_VSCROLL,SB_LINEUP,0);
    end;
  end;
end;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM