当Image载入图片后 ScrollBox 自动出现了相应的滚动条 目前我的代码可以实现在Image的大小范围内拖动Image 但效果不是很好 有残影 var
MouseX,MouseY: integer;procedure TFormMain.ImageViewMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
MouseX := X;
MouseY := Y;
end;procedure TFormMain.ImageMaskMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
function zf(x:integer):shortint ; //取x符号
begin
result:= 0;
if x > 0 then
result:=1;
if x < 0 then
result:= -1;
end;
begin //移动图片
if (shift = [ssleft]) and (ImageView.Picture.Bitmap.Empty = false) then
begin
if abs(x-MouseX) >5 then
begin
ScrollBox1.HorzScrollBar.Position :=ScrollBox1.HorzScrollBar.Position - zf(x-MouseX);
end;
if abs(y-MouseY) > 5 then
begin
ScrollBox1.VertScrollBar.Position :=ScrollBox1.VertScrollBar.Position - zf(y-MouseY);
end;
end;
end;
以上代码也是从另一位朋友的代码中学来的 我想应该有更好的办法 哪位高手帮忙指点指点 谢谢!
在Image下面放一个Panel,设置Panel的BevelOuter属性为bvNone,然后设置image的Aligh属性为clClient,然后处理image的mousedown事件:
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
Panel1.Perform(WM_SYSCOMMAND,$f012,0)
end;
谢谢xixuemao(从哪里跌倒就要从哪里抬出去) 图是拖着动了 但是跟ScrollBox却关联不上了 我想要的效果相当于实时调整ScrollBox的滚动条