我的scrollbox里显示的是一张timage
在scrollbox的MouseWheel里添:
ScrollBox1.VertScrollBar.Position := ScrollBox1.VertScrollBar.Position - WheelDelta;
滚动滚轮的时候没反应,设中断发现没有执行这是为什么
在scrollbox的MouseWheel里添:
ScrollBox1.VertScrollBar.Position := ScrollBox1.VertScrollBar.Position - WheelDelta;
滚动滚轮的时候没反应,设中断发现没有执行这是为什么
begin
Image1.OnMouseDown := ScrollBox1.OnMouseDown;///ScrollBox上的Image得到鼠标事件(如点击)时,激活Scrollbox
end;procedure TForm1.ScrollBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ScrollBox1.SetFocus;//激活Scrollbox, 使之获得焦点
end;
一般情况下,使用scrollbox均需要重新给定焦点。
也可以直接给整个form重写鼠标滚轮事件,让其响应。
Procedure WMMouseWheel(Var Msg :TWMMouseWheel); Message WM_MOUSEWHEEL;
Procedure TForm1.WMMouseWheel(Var Msg :TWMMouseWheel);
begin
inherited;
if msg.WheelDelta > 0 then
SendMessage(scrData.Handle,WM_VSCROLL,SB_PAGEUP,0)
else
SendMessage(scrData.Handle,WM_VSCROLL,SB_PAGEDOWN,0);
end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, xmldom, XMLIntf, msxmldom, XMLDoc, Sockets, ExtCtrls;type
TForm1 = class(TForm)
Button1: TButton;
XMLDocument1: TXMLDocument;
ScrollBox1: TScrollBox;
TcpClient1: TTcpClient;
Edit1: TEdit;
Image1: TImage;
private
function DoMouseWheel(Shift: TShiftState; WheelDelta: Integer;
MousePos: TPoint): Boolean; override;//覆盖基类的鼠标滚动方法
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}function TForm1.DoMouseWheel(Shift: TShiftState; WheelDelta: Integer;
MousePos: TPoint): Boolean;
begin
//此虚拟方法是TWinControl捕获鼠标滚动消息时派发出来的,把你刚才的代码直接挪到这里
ScrollBox1.VertScrollBar.Position := ScrollBox1.VertScrollBar.Position - WheelDelta;
end;end.