我用一个TScrollBox控件上面放一个Tmage控件ScrollBox使用的是上下和左右的滚动条当Tmage导入的图片大于TScrollBox的窗口时上下和左右的滚动条出现。这样只能通过调节滚动条来看没有出现的部分。在TScrollBox窗口不改变大小的情况下我想实现鼠标放在图片上面的时候出现一个小手按左键拖动看没有出现的部分,类似ACDSee的样子。怎么实现,请给段代码吧!另外,怎么打印图片?能给段代码吗?
调试欢乐多
Form1: TForm1;
BgnPoint: TPoint;procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Image1.BeginDrag(False);
BgnPoint.x := X;
BgnPoint.y := y;
end;procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Image1.EndDrag(False);
end;procedure TForm1.Image1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
if Image1.Dragging then
begin
ScrollBox1.HorzScrollBar.Position := ScrollBox1.HorzScrollBar.Position - X + BgnPoint.X;
ScrollBox1.VertScrollBar.Position := ScrollBox1.VertScrollBar.Position - Y + BgnPoint.Y;
end;
end;procedure TForm1.Image1Click(Sender: TObject);
begin
Image1.BeginDrag(False);
end;
var
FormImage: TBitmap;
Info: PBitmapInfo;
InfoSize: DWORD;
Image: Pointer;
ImageSize: DWORD;
Bits: HBITMAP;
DIBWidth, DIBHeight: Longint;
PrintWidth, PrintHeight: Longint;
begin
Printer.BeginDoc;
try
FormImage := GetFormImage;
Canvas.Lock;
try
{ Paint bitmap to the printer }
with Printer, Canvas do
begin
Bits := FormImage.Handle;
GetDIBSizes(Bits, InfoSize, ImageSize);
Info := AllocMem(InfoSize);
try
Image := AllocMem(ImageSize);
try
GetDIB(Bits, 0, Info^, Image^);
with Info^.bmiHeader do
begin
DIBWidth := biWidth;
DIBHeight := biHeight;
end;
case PrintScale of
poProportional:
begin
PrintWidth := MulDiv(DIBWidth, GetDeviceCaps(Handle,
LOGPIXELSX), PixelsPerInch);
PrintHeight := MulDiv(DIBHeight, GetDeviceCaps(Handle,
LOGPIXELSY), PixelsPerInch);
end;
poPrintToFit:
begin
PrintWidth := MulDiv(DIBWidth, PageHeight, DIBHeight);
if PrintWidth < PageWidth then
PrintHeight := PageHeight
else
begin
PrintWidth := PageWidth;
PrintHeight := MulDiv(DIBHeight, PageWidth, DIBWidth);
end;
end;
else
PrintWidth := DIBWidth;
PrintHeight := DIBHeight;
end;
StretchDIBits(Canvas.Handle, 0, 0, PrintWidth, PrintHeight, 0, 0,
DIBWidth, DIBHeight, Image, Info^, DIB_RGB_COLORS, SRCCOPY);
finally
FreeMem(Image, ImageSize);
end;
finally
FreeMem(Info, InfoSize);
end;
end;
finally
Canvas.Unlock;
FormImage.Free;
end;
finally
Printer.EndDoc;
end;
end;