?? prvieweh.pas
字號:
HorzScrollBar.Tracking := True;
VertScrollBar.Tracking := True;
FScalePercent := 100;
end;
destructor TPreviewBox.Destroy;
begin
FreeAndNil(FPrinter);
inherited;
end;
procedure TPreviewBox.CreateParams(var Params: TCreateParams);
const
BorderStyles: array[TBorderStyle] of DWORD = (0, WS_BORDER);
begin
inherited CreateParams(Params);
Params.Style := Params.Style or WS_CLIPCHILDREN;
end;
procedure TPreviewBox.KeyDown(var Key: Word; Shift: TShiftState);
begin
inherited;
with VertScrollBar do
case Key of
VK_UP:
if ssCtrl in Shift then Position := Position - ClientHeight + Increment
else Position := Position - Increment;
VK_Down:
if ssCtrl in Shift then Position := Position + ClientHeight - Increment
else Position := Position + Increment;
VK_Prior:
if ssCtrl in Shift then Position := 0
else Position := Position - ClientHeight + Increment;
VK_Next:
if ssCtrl in Shift then Position := Range
else Position := Position + ClientHeight - Increment;
end;
with HorzScrollBar do
case Key of
VK_Left:
if ssCtrl in Shift then Position := Position - ClientWidth + Increment
else Position := Position - Increment;
VK_Right:
if ssCtrl in Shift then Position := Position + ClientWidth - Increment
else Position := Position + Increment;
VK_Home:
if ssCtrl in Shift then
begin
Position := 0;
VertScrollBar.Position := 0;
end
else Position := 0;
VK_End:
if ssCtrl in Shift then
begin
Position := Range;
VertScrollBar.Position := VertScrollBar.Range;
end
else Position := Range;
end;
end;
procedure TPreviewBox.MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
begin
SetFocus;
end;
procedure TPreviewBox.PrintDialog;
var Page: Integer;
OldPrinter: TPrinter;
begin
OldPrinter := PrintersSetPrinter(Printer.Printer);
try
with TPrintDialog.Create(Owner) do
try
Options := Options + [poPageNums];
MinPage := 1;
MaxPage := PageCount;
FromPage := 1;
ToPage := PageCount;
if Execute then
if Assigned(Printer) then
begin
if Printer.FMetafileList.Count = 0 then Exit;
with PrintersPrinter do
begin
BeginDoc;
for Page := FromPage to ToPage do
begin
Printer.DrawPage(Printer, Canvas, Page);
if Page < ToPage then NewPage;
end;
EndDoc;
end;
end;
finally
Free;
end;
finally
PrintersSetPrinter(OldPrinter);
end;
end;
procedure TPreviewBox.PrinterSetupDialog;
var OldPrinter: TPrinter;
begin
OldPrinter := PrintersSetPrinter(Printer.Printer);
try
if Assigned(OnPrinterSetupDialog) then
OnPrinterSetupDialog(Self)
else
with TPrinterSetupDialog.Create(Owner) do
try
if Execute then
begin
UpdatePageSetup;
if Assigned(FOnPrinterSetupChanged)
then FOnPrinterSetupChanged(Self);
end;
finally
Free;
end;
finally
PrintersSetPrinter(OldPrinter);
end;
end;
procedure TPreviewBox.SetPageIndex(Value: Integer);
begin
if Value < 1 then Value := 1;
if Value > PageCount then Value := PageCount;
if Value <> FPageIndex then
begin
FPageIndex := Value;
UpdatePreview;
if Assigned(OnPrinterPreviewChanged) then OnPrinterPreviewChanged(Self);
end;
end;
procedure TPreviewBox.SetPrinter(const Value: TPrinterPreview);
begin
FPrinter := Value;
end;
procedure TPreviewBox.SetViewMode(const Value: TViewMode);
begin
if Value <> FViewMode then
begin
FViewMode := Value;
UpdatePageSetup;
end;
if Assigned(OnPrinterPreviewChanged) then OnPrinterPreviewChanged(Self);
end;
procedure TPreviewBox.UpdatePageSetup;
var
Scaling: Integer;
ALeft, ATop, AWidth, AHeight: Integer;
begin
// pnlShadow.Visible:=False;
// LockWindowUpdate(Handle);
try
with FDrawPanel, Printer do
begin
ALeft := Left; ATop := Top; AWidth := Width; AHeight := Height;
// Visible:=False;
case FViewMode of
vm500: Scaling := 500;
vm200: Scaling := 200;
vm150: Scaling := 150;
vm100: Scaling := 100;
vm75: Scaling := 75;
vm50: Scaling := 50;
vm25: Scaling := 25;
vm10: Scaling := 10;
vmPageWidth: // on width pages
begin
VertScrollBar.Position := 0;
HorzScrollBar.Position := 0;
Scaling := 1;
ALeft := 8;
ATop := 8;
AWidth := Self.Width - 20 - GetSystemMetrics(sm_CXVScroll);
if Printer.Printers.Count > 0 then
begin
AHeight := AWidth * GetDeviceCaps(Printer.Handle, VertSize) div
GetDeviceCaps(Printer.Handle, HorzSize);
FScalePercent := AWidth * 100 div (PageWidth * (Self.Owner as TForm).PixelsPerInch div
GetDeviceCaps(Printer.Handle, LOGPIXELSX));
end else
begin
AHeight := AWidth * DefaultPrinterVerticalSizeMM div
DefaultPrinterHorizontalSizeMM;
FScalePercent := AWidth * 100 div (PageWidth * (Self.Owner as TForm).PixelsPerInch div
DefaultPrinterPixelsPerInchX);
end;
VertScrollBar.Range := AHeight + 16;
HorzScrollBar.Range := 0;
end;
vmFullPage: // 耱疣龕鱘 鰣腓覲? begin
Scaling := 1;
VertScrollBar.Range := 0;
HorzScrollBar.Range := 0;
VertScrollBar.Position := 0;
HorzScrollBar.Position := 0;
AHeight := Self.ClientHeight - 16;
if Printer.Printers.Count > 0 then
AWidth := AHeight * GetDeviceCaps(Printer.Handle, HorzSize) div
GetDeviceCaps(Printer.Handle, VertSize)
else
AWidth := AHeight * DefaultPrinterHorizontalSizeMM div
DefaultPrinterVerticalSizeMM;
if AWidth > Self.ClientWidth - 16 then
begin
AWidth := Self.ClientWidth - 16;
if Printer.Printers.Count > 0 then
AHeight := AWidth * GetDeviceCaps(Printer.Handle, VertSize) div
GetDeviceCaps(Printer.Handle, HorzSize)
else
AHeight := AWidth * DefaultPrinterVerticalSizeMM div
DefaultPrinterHorizontalSizeMM;
end;
ALeft := (Self.ClientWidth - AWidth) div 2;
ATop := (Self.ClientHeight - AHeight) div 2;
FScalePercent := 100;
end;
else Scaling := 1;
end;
case FViewMode of
vm500..vm10:
begin
VertScrollBar.Position := 0;
HorzScrollBar.Position := 0;
ALeft := 8;
ATop := 8;
if Printer.Printers.Count > 0 then
begin
// AWidth := Scaling * PageWidth * (Self.Owner as TForm).PixelsPerInch div
AWidth := Scaling * PageWidth * Screen.PixelsPerInch div
GetDeviceCaps(Printer.Handle, LOGPIXELSX) div 100;
AHeight := AWidth * GetDeviceCaps(Printer.Handle, VertSize) div
GetDeviceCaps(Printer.Handle, HorzSize);
end else
begin
// AWidth := Scaling * PageWidth * (Self.Owner as TForm).PixelsPerInch div
AWidth := Scaling * PageWidth * Screen.PixelsPerInch div
DefaultPrinterPixelsPerInchX div 100;
AHeight := AWidth * DefaultPrinterVerticalSizeMM div
DefaultPrinterHorizontalSizeMM;
end;
VertScrollBar.Range := AHeight + 16;
HorzScrollBar.Range := AWidth + 16;
if (AWidth + 16) < Self.ClientWidth then
ALeft := (Self.ClientWidth - AWidth) div 2;
if (AHeight + 16) < Self.ClientHeight then
ATop := (Self.ClientHeight - AHeight) div 2;
FScalePercent := Scaling;
end;
end;
//Visible:=True;
end;
FDrawPanel.Invalidate;
FDrawPanel.SetBounds(ALeft, ATop, AWidth, AHeight);
pnlShadow.SetBounds(FDrawPanel.Left + 4, FDrawPanel.Top + 4, FDrawPanel.Width, FDrawPanel.Height);
//pnlShadow.Visible:=True;
finally
// LockWindowUpdate(0);
end;
end;
procedure TPreviewBox.UpdatePreview;
begin
Invalidate;
FDrawPanel.Invalidate;
{ with FDrawPanel do
begin
Hide;
Show;
end;}
end;
procedure TPreviewBox.WMGetDlgCode(var Msg: TWMGetDlgCode);
begin
Msg.Result := DLGC_WANTARROWS;
end;
procedure TPreviewBox.WMSize(var Message: TWMSize);
begin
inherited;
if (ViewMode in [vmPageWidth, vmFullPage]) or
((FDrawPanel.Width + 16) < ClientWidth) or
((FDrawPanel.Height + 16) < ClientHeight) then
UpdatePageSetup;
end;
procedure TPreviewBox.SetPrinterSetupOwner(const Value: TComponent);
begin
if FPrinterSetupOwner = Value then Exit;
FPrinterSetupOwner := Value;
if Assigned(Value) then FPrinterSetupOwner.FreeNotification(Self);
if Assigned(OnPrinterPreviewChanged) then OnPrinterPreviewChanged(Self);
end;
procedure TPreviewBox.Notification(AComponent: TComponent; Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (AComponent = PrinterSetupOwner)
then PrinterSetupOwner := nil;
end;
function TPreviewBox.DoMouseWheelDown(Shift: TShiftState; MousePos: TPoint): Boolean;
begin
Result := inherited DoMouseWheelDown(Shift, MousePos);
if not Result then
begin
with VertScrollBar do
if Range < ClientHeight
then PageIndex := PageIndex + 1
else Position := Position + Increment * Mouse.WheelScrollLines * FScalePercent div 100;
Result := True;
end;
end;
function TPreviewBox.DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean;
begin
Result := inherited DoMouseWheelUp(Shift, MousePos);
if not Result then
begin
with VertScrollBar do
if Range < ClientHeight
then PageIndex := PageIndex - 1
else Position := Position - Increment * Mouse.WheelScrollLines * FScalePercent div 100;
Result := True;
end;
end;
{ TPrinterPreview }
constructor TPrinterPreview.Create;
begin
inherited Create;
FMetafileList := TList.Create;
FPrinter := TPrinter.Create;
end;
destructor TPrinterPreview.Destroy;
var i: Integer;
begin
for i := 0 to FMetafileList.Count - 1 do
TMetaFile(FMetafileList[i]).Free;
FreeAndNil(FMetafileList);
FreeAndNil(FPrinter);
inherited Destroy;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -