Solved

how to use TPrintDialog to print?

Posted on 1998-08-15
23
1,060 Views
Last Modified: 2010-04-04
how to use TPrintDialog to print contents ,but the print dialog form don't appear?
0
Comment
Question by:lhlplmy
[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
  • 9
  • 6
  • 3
  • +3
23 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1335129
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
 

Author Comment

by:lhlplmy
ID: 1335130
i want the printer dialog form don't appear in the desktop.how to do it?
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1335131
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:erajoj
ID: 1335132
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
 
LVL 4

Expert Comment

by:erajoj
ID: 1335133
BTW, check at the end, not at the beginning...

/// John
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1335134
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
 
LVL 2

Expert Comment

by:333
ID: 1335135
Use TPrinter instead of TPrintDialog
0
 

Author Comment

by:lhlplmy
ID: 1335136
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
 
LVL 4

Expert Comment

by:erajoj
ID: 1335137
Huh?
Sorry! I still don't seem to understand what you want.

/// John
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1335138
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
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1335139
???

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
 

Author Comment

by:lhlplmy
ID: 1335140
     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
 
LVL 8

Expert Comment

by:ZifNab
ID: 1335141
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
 
LVL 8

Expert Comment

by:ZifNab
ID: 1335142
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
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1335143
or use property printerindex to select the printer.
(-1 = default printer)

Black Death.
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1335144
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
 
LVL 8

Expert Comment

by:ZifNab
ID: 1335145
same problem here.
0
 

Author Comment

by:lhlplmy
ID: 1335146
ok , thank you ,zifnab.
you 'd better lock the question.

and I have another problem waiting for answer,can you help me?
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1335147
lhlplmy,

 Is everything working now?

Zif.
0
 

Author Comment

by:lhlplmy
ID: 1335148
zif,
thank you .It's ok now.


0
 
LVL 8

Accepted Solution

by:
ZifNab earned 90 total points
ID: 1335149
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
 

Author Comment

by:lhlplmy
ID: 1335150
Adjusted points to 90
0
 

Expert Comment

by:glabax
ID: 1335151
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

739 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