Autor Beitrag
fidionael
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 232

Win XP SP2, Ubuntu 6.06
Delphi 7 PE, Delphi 3 Prof
BeitragVerfasst: Di 01.01.08 19:45 
Hallo,

ich versuche gerade mir das Drucken in Delphi anzueignen und versuche nun ein Sudoku-Feld zu drucken. Die Seite die aus dem Drucker kommt ist jedoch immer leer. Hier mal der Quelltext:

ausblenden Auszug aus Unit1.pas
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TForm1.Drucken1Click(Sender: TObject);
begin
  if PrintDialog1.Execute then begin
    Printer.BeginDoc;
    SetMapMode(Printer.Canvas.Handle,MM_LOMETRIC);
    Printer.Canvas.TextOut(250,250,'Sudoku');
    MeinSpielfeld.Draw(Printer.Canvas,
      250,250 + Printer.Canvas.Font.Height + 10,
      (GetDeviceCaps(Printer.Canvas.Handle,HORZSIZE)*10) - 500,
      (GetDeviceCaps(Printer.Canvas.Handle,HORZSIZE)*10) - 500);
    Printer.EndDoc;
  end;
end;


ausblenden Auszug aus Spielfeld.pas
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:
procedure TSudoku.Draw(fCanvas: TCanvas;fX,fY,fWidth,fHeight: Integer);
var i,j: Integer;
begin with fCanvas do begin
  // Löschen der Leinwand
  Brush.Color := clWhite;;
  FillRect(rect(fX,fY,fX+fWidth,fY+fHeight));
  // Pinseleigenschaften
  Pen.Color := 0; Pen.Width := fWidth div 150;
  // Rahmen
  MoveTo(fX,fY); LineTo(fX+fWidth,fY); LineTo(fX+fWidth,fY+fHeight);
  LineTo(fX,fY+fHeight); LineTo(fX,fY);
  // Einzelne Quadrate
  MoveTo((fX+fWidth) div 3,fY); LineTo((fX+fWidth) div 3,fY+fHeight);
  MoveTo(((fX+fWidth) div 3)*2,fY); LineTo(((fX+fWidth) div 3)*2,fY + fHeight);
  MoveTo(fX,(fY+fHeight) div 3); LineTo(fX+fWidth,(fY+fHeight) div 3);
  MoveTo(fX,((fY+fHeight) div 3)*2); LineTo(fX+fWidth,((fY+fHeight) div 3)*2);
  // Einzelne Kästchen
  Pen.Width := Pen.Width div 2;
  for i := 1 to 8 do if not (i mod 3 = 0then begin
    MoveTo(((fX+fWidth) div 9)*i+Pen.Width * 2,fY);
    LineTo(((fX+fWidth) div 9)*i+Pen.Width * 2,fY+fHeight);
    MoveTo(fX,((fY+fHeight) div 9)*i+Pen.Width * 2);
    LineTo(fX+fWidth,((fY+fHeight) div 9)*i+Pen.Width * 2);
  end;
endend;


Das Zeichnen auf einer Formular- oder Imagecanvas funktioniert einwandfrei. Ich bekomme auch eine Ausgabe wenn ich die Zeile SetMapMode(Printer.Canvas.Handle,MM_LOMETRIC); entferne, welche allerdings nicht ansatzweise so aussieht wie ich mir das vorstelle.

Kann mir jemand weiterhelfen?
LorenzS
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 128

MS-DOS, WIN 7, WIN 10
BP7.0, D3, D5
BeitragVerfasst: Di 01.01.08 19:51 
vlt brauchst du auch nur ne lupe
fidionael Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 232

Win XP SP2, Ubuntu 6.06
Delphi 7 PE, Delphi 3 Prof
BeitragVerfasst: Di 01.01.08 19:52 
Es war so gedacht, dass er die Zeichnung auf Seitenbreite streckt. Wenn es so nicht funktioniert, wie dann?
LorenzS
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 128

MS-DOS, WIN 7, WIN 10
BP7.0, D3, D5
BeitragVerfasst: Di 01.01.08 20:11 
ohne SetMapMode(Printer.Canvas.Handle,MM_LOMETRIC); gibt es wenigstens ein bild

irgendwie ist die seit leer siehe pdf:

achja Printer.Canvas.Font.Height ist immer negative
Einloggen, um Attachments anzusehen!
LorenzS
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 128

MS-DOS, WIN 7, WIN 10
BP7.0, D3, D5
BeitragVerfasst: Di 01.01.08 20:51 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure TForm1.Drucken1Click(Sender: TObject);
var rand:integer;
begin
 if PrintDialog1.Execute then
 begin
  Printer.BeginDoc;
  rand:=printer.PageWidth shr 3// div 8 = 1 inch
  Printer.Canvas.TextOut(rand,rand,'Sudoku');
  MeinSpielfeld.Draw(Printer.Canvas,
   rand,rand + (-Printer.Canvas.Font.Height) + 10,printer.PageWidth-rand*2,
   printer.PageWidth-rand*2);
  Printer.EndDoc;
 end;
end;

ausblenden 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:
procedure TSudoku.Draw(fCanvas: TCanvas;fX,fY,fWidth,fHeight: Integer);
var i,j: Integer;
begin
 with fCanvas do
 begin
  // Löschen der Leinwand
  Brush.Color := clWhite;;
  FillRect(rect(fX,fY,fX+fWidth,fY+fHeight));
  // Pinseleigenschaften
  Pen.Color := 0; Pen.Width := fWidth div 150;
  // Rahmen
  MoveTo(fX,fY); LineTo(fX+fWidth,fY); LineTo(fX+fWidth,fY+fHeight);
  LineTo(fX,fY+fHeight); LineTo(fX,fY);
  // Einzelne Quadrate
  MoveTo(fX+ fWidth div 3   ,fY); LineTo(fX+ fWidth div 3   ,fY + fHeight);
  MoveTo(fX+(fWidth div 3)*2,fY); LineTo(FX+(fWidth div 3)*2,fY + fHeight);
  MoveTo(fX,fY+ fHeight div 3   ); LineTo(fX+fWidth,fY+ fHeight div 3);
  MoveTo(fX,fY+(fHeight div 3)*2); LineTo(fX+fWidth,fY+(fHeight div 3)*2);
  // Einzelne Kästchen
  Pen.Width := Pen.Width div 2;
  for i := 1 to 8 do
   if (i mod 3 <> 0then
   begin
    MoveTo(fX+(fWidth div 9)*i+Pen.Width * 2,fY);
    LineTo(fX+(fWidth div 9)*i+Pen.Width * 2,fY+fHeight);
    MoveTo(fX       ,fY+(fHeight div 9)*i+Pen.Width * 2);
    LineTo(fX+fWidth,fY+(fHeight div 9)*i+Pen.Width * 2);
   end;
 end;
end;
Einloggen, um Attachments anzusehen!
fidionael Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 232

Win XP SP2, Ubuntu 6.06
Delphi 7 PE, Delphi 3 Prof
BeitragVerfasst: Mi 02.01.08 06:45 
Vielen Dank!