Autor Beitrag
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Sa 13.08.05 16:46 
Hi!

Suche eine Möglichkeit, das Druckformat (bzw. das Papierformat, also A5, A4, ...) umzustellen. Ich glaube nicht, dass das per Printer-Objekt geht, aber es wäre mir sehr recht, wenn es denn ginge.
Ich bin auch für andere Möglichkeiten offen - die über den PrintDialog funktioniert allerdings nicht (Einstellungen werden nicht beibehalten).

Hier der Code, um den es geht:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
procedure TPrinterConfigForm.OKButtonClick(Sender: TObject);
const
  CopyrightText: String = 'Printed with Complex Calculator - (c) by Dust Signs Andreas Unterweger 2005';
var
  ScalingFactor: Integer; //Skalierungsfaktor für Bild
begin
  Printer.PrinterIndex := PrinterComboBox.ItemIndex; //Einstellungen übernehmen (Drucker)
  if PortraitRadioButton.Checked then //Format
    Printer.Orientation := poPortrait
  else
    Printer.Orientation := poLandscape;
  Printer.Title := 'Complex Calculator Printing Job';
  Printer.BeginDoc;
  Hide; //Fenster verstecken (soll ja nicht auf dem Bild sein ;)
  with MainForm do begin //Verwendung von PaintBox-Maßen aus dem Hauptfenster
    PaintBox1Paint(Sender); //Anzeige aktualisieren
    if ScaleCheckBox.Checked then begin //Skalieren?
      ScalingFactor := Printer.PageWidth div PaintBox1.Width * 8 div 10; //Skalierungsfaktor berechnen (80% Größe da 2x10% Rand!)
      StretchBlt(Printer.Canvas.Handle, Printer.PageWidth * 1 div 10, Printer.PageHeight div 2 - ScalingFactor * PaintBox1.Height div 2, Printer.PageWidth * 8 div 10, ScalingFactor * PaintBox1.Height, PaintBox1.Canvas.Handle, 0, 0, PaintBox1.Width, PaintBox1.Height, SRCCOPY); //Canvasinhalt kopieren
    with Printer.Canvas do begin //Rahmen und Text
      Brush.Style := bsClear;
      if BoxCheckBox.Checked then //Rahmen?
        Rectangle(Printer.PageWidth * 1 div 10, Printer.PageHeight div 2 - ScalingFactor * PaintBox1.Height div 2, Printer.PageWidth * 9 div 10, Printer.PageHeight div 2 + ScalingFactor * PaintBox1.Height div 2); //Rand
      TextOut(Printer.PageWidth * 9 div 10 - TextWidth(CopyrightText), Printer.PageHeight div 2 + ScalingFactor * PaintBox1.Height div 2 + 5, CopyrightText); //Copyrighttext hinzufügen
      end;
    end else begin //Keine Skalierung
      StretchBlt(Printer.Canvas.Handle, Printer.PageWidth div 2 - PaintBox1.Width div 2, Printer.PageHeight div 2 - PaintBox1.Height div 2, PaintBox1.Width, PaintBox1.Height, PaintBox1.Canvas.Handle, 0, 0, PaintBox1.Width, PaintBox1.Height, SRCCOPY); //Canvasinhalt kopieren
      with Printer.Canvas do begin //Rahmen und Text
        Brush.Style := bsClear;
        if BoxCheckBox.Checked then //Rahmen?
          Rectangle(Printer.PageWidth div 2 - PaintBox1.Width div 2, Printer.PageHeight div 2 - PaintBox1.Height div 2, Printer.PageWidth div 2 + PaintBox1.Width div 2, Printer.PageHeight div 2 + PaintBox1.Height div 2); //Rand
        TextOut(Printer.PageWidth div 2 - TextWidth(CopyrightText) div 2, Printer.PageHeight div 2 + PaintBox1.Height div 2 + 5, CopyrightText); //Copyrighttext hinzufügen
        end;
      end;
    end;
  Printer.EndDoc;
  Close;
end;


Stört euch nicht an den komplizieren Anordnungskoordinaten. Ziel des Spiels ist es jetzt, ein frei wählbares Papierformat hier irgendwie einzubauen (Ergebnis sieht dann aus wie der Anhang). Irgendjemand eine Idee?

AXMD
Einloggen, um Attachments anzusehen!
AXMD Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Sa 13.08.05 17:01 
Upsi :oops: Hab Mist gebaut mit dem PrintDialog... Jetzt funktioniert's... Falls jemand eine Lösung mit TPrinter hat bitte trotzdem posten.

Danke
AXMD