Autor |
Beitrag |
fidionael
      
Beiträge: 232
Win XP SP2, Ubuntu 6.06
Delphi 7 PE, Delphi 3 Prof
|
Verfasst: 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:
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; |
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 Brush.Color := clWhite;; FillRect(rect(fX,fY,fX+fWidth,fY+fHeight)); Pen.Color := 0; Pen.Width := fWidth div 150; MoveTo(fX,fY); LineTo(fX+fWidth,fY); LineTo(fX+fWidth,fY+fHeight); LineTo(fX,fY+fHeight); LineTo(fX,fY); 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); Pen.Width := Pen.Width div 2; for i := 1 to 8 do if not (i mod 3 = 0) then 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; |
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
      
Beiträge: 128
MS-DOS, WIN 7, WIN 10
BP7.0, D3, D5
|
Verfasst: Di 01.01.08 19:51
vlt brauchst du auch nur ne lupe
|
|
fidionael 
      
Beiträge: 232
Win XP SP2, Ubuntu 6.06
Delphi 7 PE, Delphi 3 Prof
|
Verfasst: 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
      
Beiträge: 128
MS-DOS, WIN 7, WIN 10
BP7.0, D3, D5
|
Verfasst: 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
      
Beiträge: 128
MS-DOS, WIN 7, WIN 10
BP7.0, D3, D5
|
Verfasst: Di 01.01.08 20:51
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; 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; |
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 Brush.Color := clWhite;; FillRect(rect(fX,fY,fX+fWidth,fY+fHeight)); Pen.Color := 0; Pen.Width := fWidth div 150; MoveTo(fX,fY); LineTo(fX+fWidth,fY); LineTo(fX+fWidth,fY+fHeight); LineTo(fX,fY+fHeight); LineTo(fX,fY); 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); Pen.Width := Pen.Width div 2; for i := 1 to 8 do if (i mod 3 <> 0) then 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 
      
Beiträge: 232
Win XP SP2, Ubuntu 6.06
Delphi 7 PE, Delphi 3 Prof
|
Verfasst: Mi 02.01.08 06:45
|
|
|