• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1907
  • Last Modified:

how to use TPrintDialog to print?

how to use TPrintDialog to print contents ,but the print dialog form don't appear?
0
lhlplmy
Asked:
lhlplmy
  • 9
  • 6
  • 3
  • +3
1 Solution
 
ZifNabCommented:
hi lhlplmy,

Can you be more specific? Because this is well explained in delphi help :

This example uses a button, a Page Control, and a Print dialog box on a form. When the user clicks the button, the print dialog is displayed.  The user can select any subset of the pages in the page control for printing.  The selected pages are then printed.
To run this example successfully, you must add the Printers unit to the uses clause of your unit.

procedure TForm1.Button1Click(Sender:TObject);

var
  I, Start, Stop: Integer;
begin
PrintDialog1.Options := [poPageNums, poSelection];
PrintDialog1.FromPage := 1;
PrintDialog1.MinPage := 1;
PrintDialog1.ToPage := PageControl1.PageCount;
PrintDialog1.MaxPage := PageControl1.PageCount;
if PrintDialog1.Execute then
  begin
  { determine the range the user wants to print }
  with PrintDialog1 do
  begin
    if PrintRange = prAllPages then

      begin
      Start := MinPage - 1;
      Stop := MaxPage - 1;
      end
    else if PrintRange = prSelection then
      begin
      Start := PageControl1.ActivePage.PageIndex;
      Stop := Start;
      end
    else  { PrintRange = prPageNums }
      begin
      Start := FromPage - 1;
      Stop := ToPage - 1;
      end;
  end;
  { now, print the pages }
  with Printer do

    begin
    BeginDoc;
    for I := Start to Stop do
      begin
      PageControl1.Pages[I].PaintTo(Handle, 10, 10);
      if I <> Stop then
        NewPage;
      end;
    EndDoc;
    end;
  end;
end;

So for easy example :

1. put a button on the form
2. add the Printers unit to the uses clause of your unit

3. In the click event of the button add following code :

if Printdialog1.Excute then begin
 // do print stuff here
end
 else // user aborted print

Execute starts the printdialog and returns a boolean variable :

* false user clicked on cancel
* true user clicked on OK.

Regards, Zif.

0
 
lhlplmyAuthor Commented:
i want the printer dialog form don't appear in the desktop.how to do it?
0
 
ZifNabCommented:
lhlplmy,

Sorry misunderstanding of your Q.
 Euhm, if you don't want to show it up... Why then do you want to use it?

Zif.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
erajojCommented:
Hi,
Look at question Q.10071763.
In there is an example of mine of how to get/set printer properties w/o the printdialog.

Zif, so overworked you can't read? ;-)

/// John
0
 
erajojCommented:
BTW, check at the end, not at the beginning...

/// John
0
 
ZifNabCommented:
erajoj, reading is ok, but understanding not. :-) Thought that lhlplmy wanted to see the dialog, but that it didn't show on the screen. Zif.
0
 
333Commented:
Use TPrinter instead of TPrintDialog
0
 
lhlplmyAuthor Commented:
i want to get the contents on my canon printer , but the PrinterDialog won't appear on the screen ,otherwise i should press the 'ok' button to close the PrinterDialog ,then my canon printer work.

thank you everyone.

0
 
erajojCommented:
Huh?
Sorry! I still don't seem to understand what you want.

/// John
0
 
ZifNabCommented:
lhlplmy, what is your native language? your english is good but a little bit confusing.

please, just explain what you want :

1. Get your printer properties
   or Get your paper properties
   --> what do you want to do with it?
2. Print some stuff?

.

Zif.
0
 
BlackDeathCommented:
???

what do you mean by "contents" - the settings or maybe the queue entries?

is it possible that "PrinterDialog" in your words does not mean "TPrintDialog"??

i am sure we will be able to help you, just help us with the understanding of your question.

so long,

Black Death.
0
 
lhlplmyAuthor Commented:
     In os win95 ,the priter dialog will appear when you printe a file in Microsoft Word ,you can choose what printer to use ,how many copies you wanted ,and from which page to printe .Then
you press the 'ok' button to let the printer printe the file.
     In my program , i want to print some information(or ascii file) in memo , and i want  to  control the print  variables (about what printer to use ,how many copies ,and so on) in my program . And when i press 'print' button ,the print dialog won't appear,and  the printer print the file  . Maybe i can control the 'ok' button in print dialog , but i don't know how to do .So
the question  is that  how to avoid the printer dialog appearing  when you call the procedure TPrintDialog.Execute to print file in memo and the printer can print my file.
0
 
ZifNabCommented:
If you want to do this, you don't need to use the printdialog. The printdialog is just intended to let the user specify the printer stuff. You don't want to let the user choose, so you don't need the printerdialog! Zif.
0
 
ZifNabCommented:
lhlplmy,

You've to use the Printer unit only :

use getprinter, setprinter to get or set the printer.

To print use begindoc, enddoc :

  with Printer do
    begin
     BeginDoc;
       // put all the needed print stuff here
       // i.e. what you want to print etc.
     EndDoc;
      // with EndDoc the printer starts printing
   end;

Zif.
0
 
BlackDeathCommented:
or use property printerindex to select the printer.
(-1 = default printer)

Black Death.
0
 
BlackDeathCommented:
say, guys:

on my screen some weird solid black rectancles appear on the right of the text boxes, while these are of half the usual width. is this the same with yours?
0
 
ZifNabCommented:
same problem here.
0
 
lhlplmyAuthor Commented:
ok , thank you ,zifnab.
you 'd better lock the question.

and I have another problem waiting for answer,can you help me?
0
 
ZifNabCommented:
lhlplmy,

 Is everything working now?

Zif.
0
 
lhlplmyAuthor Commented:
zif,
thank you .It's ok now.


0
 
ZifNabCommented:
lhlplmy,

 Are you sure? So I may answer the question? Or do you want to give somebody else the points?

I now answer the Q, confering comment Monday, August 17 1998 - 06:26AM PDT. If you want to give the points to somebody else, no problem, just reject this answer.

To end this thread :

 - For the purpose you want to use TPrintdialog, you don't have to use TPrintDialog. TPrintDialog is just made for letting the user decide some printing stuff.
 - Just use TPrinter unit and it's functions for printing the contents of your memo and for making installing the page, printer, ...

Regards, ZiF.
0
 
lhlplmyAuthor Commented:
Adjusted points to 90
0
 
glabaxCommented:
I have a problem with the qreport.printersetting.printerindex
Because when i use it, i lose a the printer setup i determine in the properties of the qreport (page size ...) the print is not well.
But when i put this printer by default in windows before lunching my application it works well
What the problem ??

Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 9
  • 6
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now