Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi 如何修复TScrollBar鼠标滚轮故障?_Delphi_Scroll_Delphi 2006 - Fatal编程技术网

Delphi 如何修复TScrollBar鼠标滚轮故障?

Delphi 如何修复TScrollBar鼠标滚轮故障?,delphi,scroll,delphi-2006,Delphi,Scroll,Delphi 2006,我有一个t框架的内部,当我使用鼠标滚轮时,它不会在滚动框中上下滚动 我试着用 TScrollBox(Sender).Perform(WM_VSCROLL,1,0); 在框架上,鼠标向下旋转,但不会触发 有什么想法吗?我的滚动框如下所示: type TMyScrollBox = class(TScrollBox) protected function DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; MousePos:

我有一个
t框架的内部
,当我使用鼠标滚轮时,它不会在滚动框中上下滚动

我试着用

TScrollBox(Sender).Perform(WM_VSCROLL,1,0); 
框架上,鼠标向下旋转
,但不会触发


有什么想法吗?

我的滚动框如下所示:

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;

您可以使用
onmouseheel
事件处理程序:

ScrollBar1.OnMouseWheel := ScrollBoxMouseWheel;
...
procedure TFrame1.ScrollBoxMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
begin
  Handled := True;
  if WheelDelta < 0 then
    TScrollBox(Sender).VertScrollBar.Position := TScrollBox(Sender).VertScrollBar.Position + TScrollBox(Sender).VertScrollBar.Increment 
  else
    TScrollBox(Sender).VertScrollBar.Position := TScrollBox(Sender).VertScrollBar.Position - TScrollBox(Sender).VertScrollBar.Increment;
end;
ScrollBar1.OnMouseWheel:=ScrollBoxMouseWheel;
...
过程TFrame1.ScrollBoxMouseWheel(发送方:ToObject;Shift:TShiftState;WheelDelta:Integer;鼠标点:TPoint;变量处理:Boolean);
开始
已处理:=真;
如果WheelDelta<0,则
TScrollBox(发送方).VertScrollBar.Position:=TScrollBox(发送方).VertScrollBar.Position+TScrollBox(发送方).VertScrollBar.Increment
其他的
TScrollBox(发送方).VertScrollBar.Position:=TScrollBox(发送方).VertScrollBar.Position-TScrollBox(发送方).VertScrollBar.Increment;
结束;

David,滚动框(一个孩子)不应该接收
CM\u鼠标轮
,而不是
WM\u鼠标轮
(只是猜测,没有Delphi的帮助)?@David:我是在回应你上面的“解释原因”评论。为什么当你被问到时会出现“完美”的快照?“它区分了普通Windows消息和内部创建/发送的消息”并不是一个解释?我觉得说得很清楚。不过,我想我应该预料到的。我什么时候学习?sigh@Ken但我不想处理CM。我在问为什么在这里应该优先选择CM。我不是想知道WM和CM之间的区别。你明白我的意思吗?抱歉折断。@kobik H车轮通常不是车轮。轮子可以向左或向右推,以模拟页面左/右。它对我有效,但不是以这种方式。我必须使用表单本身的ScrollBoxMouseWheel事件,并用scrollbox的名称替换TScrollBox(发送者)。