?
Solved

Print job

Posted on 2003-11-18
9
Medium Priority
?
298 Views
Last Modified: 2010-04-06
I have a from with a StringGrid and some data in it
I want to print this from on a printer
i use PrintDialog
i use PrintDialog1.Execute
on the dialog box i select the right printer but when i click OK nothing happend
i read over the internet some examples
i see PrinDialog.BeginDoc but give me error undeclared identifier BeginDoc
i use also the Delphi unit Printers
But nothing happend also
Tell me how can i print my form
Thanks
0
Comment
Question by:fradolcino
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 8

Expert Comment

by:gmayo
ID: 9770490
The PrintDialog doesn't do the printing, it simply allows you to select the printer. Use the unit Printers. In your code use Printer.BeginDoc etc.

Geoff M.
0
 

Author Comment

by:fradolcino
ID: 9770534
Perhaps gmayo don't read all my comments
I specify a use Printers unit but the same error
Thanks
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9770538
a sample from the delphi online help:

procedure TForm1.Button1Click(Sender: TObject);
var
  r: TRect;
  i: Integer;
begin
  with Printer do
    begin
      r := Rect(200,200,(Pagewidth - 200),(PageHeight - 200));
      BeginDoc;
      Canvas.Brush.Style := bsClear;
      for i := 0 to Memo1.Lines.Count do
       Canvas.TextOut(200,200 + (i *
                   Canvas.TextHeight(Memo1.Lines.Strings[i])),
                   Memo1.Lines.Strings[i]);

      Canvas.Brush.Color := clBlack;
      Canvas.FrameRect(r);
      EndDoc;
    end;
end;

meikl ;-)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 8

Expert Comment

by:gmayo
ID: 9770792
I did. Perhaps you didn't read mine, in which I said:
"use Printer.BeginDoc".

Geoff M.
0
 

Author Comment

by:fradolcino
ID: 9770882
thanks meikl
but i have a StringGrid
Whould you advice me how to print the StringGrid
Thanks
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9770928
this is not so easy,
because u have to draw the grid
byself on the printer-canvas or
u could use the paintto-method for this

go to
www.torry.net
there are some stringgrids with printing support

meikl ;-)
0
 
LVL 2

Expert Comment

by:gangsterboss
ID: 9773243
to print a form just put

procedure button1click (Sender:TObject);
begin
form1.print;
end;

0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9773838
funny gangsterboss :-))

and if the content does not fit on the form?
0
 
LVL 2

Accepted Solution

by:
gangsterboss earned 220 total points
ID: 9775719
well i didn't realy think about that but u could make everything u need large enough to display all of the content eg

var i,j :integer;
begin
i:=stringgrid1.width;
j:=stringgrid1.height;
stringgrid1.width:= stringgrid1.colwidth*stringgrid1.colcount;
stringgrid1.height:= stringgrid1.rowwidth*stringgrid1.rowcount;
form1.width:= form1.width + (stringgrid1.width-i)
form1.height:= form1.height+ (stringgrid1.height-j)
form1.print
end;

but heres some could to just print the stringgrid with a title

uses
  Printers;

procedure PrintGrid(sGrid: TStringGrid; sTitle: string);
var
  X1, X2: Integer;
  Y1, Y2: Integer;
  TmpI: Integer;
  F: Integer;
  TR: TRect;
begin
  Printer.Title := sTitle;
  Printer.BeginDoc;
  Printer.Canvas.Pen.Color  := 0;
  Printer.Canvas.Font.Name  := 'Times New Roman';
  Printer.Canvas.Font.Size  := 12;
  Printer.Canvas.Font.Style := [fsBold, fsUnderline];
  Printer.Canvas.TextOut(0, 100, Printer.Title);
  for F := 1 to sGrid.ColCount - 1 do  
  begin
    X1 := 0;
    for TmpI := 1 to (F - 1) do
      X1 := X1 + 5 * (sGrid.ColWidths[TmpI]);
    Y1 := 300;
    X2 := 0;
    for TmpI := 1 to F do
      X2 := X2 + 5 * (sGrid.ColWidths[TmpI]);
    Y2 := 450;
    TR := Rect(X1, Y1, X2 - 30, Y2);
    Printer.Canvas.Font.Style := [fsBold];
    Printer.Canvas.Font.Size := 7;
    Printer.Canvas.TextRect(TR, X1 + 50, 350, sGrid.Cells[F, 0]);
    Printer.Canvas.Font.Style := [];
    for TmpI := 1 to sGrid.RowCount - 1 do  
    begin
      Y1 := 150 * TmpI + 300;
      Y2 := 150 * (TmpI + 1) + 300;
      TR := Rect(X1, Y1, X2 - 30, Y2);
      Printer.Canvas.TextRect(TR, X1 + 50, Y1 + 50, sGrid.Cells[F, TmpI]);
    end;
  end;
  Printer.EndDoc;
end;


//Examplem

procedure TForm1.Button1Click(Sender: TObject);
begin
  PrintGrid(StringGrid1, 'Title');
end;

is this ok now  kretzschmar it took me a while to write this and my 1st lang isn't english  and i only been doing delphi for about 2 months
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month8 days, 18 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question