Solved

how to use TPrintDialog to print?

Posted on 1998-08-15
23
801 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
  • 9
  • 6
  • 3
  • +3
23 Comments
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
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
Comment Utility
i want the printer dialog form don't appear in the desktop.how to do it?
0
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
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
 
LVL 4

Expert Comment

by:erajoj
Comment Utility
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
Comment Utility
BTW, check at the end, not at the beginning...

/// John
0
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
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
Comment Utility
Use TPrinter instead of TPrintDialog
0
 

Author Comment

by:lhlplmy
Comment Utility
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
Comment Utility
Huh?
Sorry! I still don't seem to understand what you want.

/// John
0
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
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
Comment Utility
???

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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:lhlplmy
Comment Utility
     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
Comment Utility
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
Comment Utility
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
Comment Utility
or use property printerindex to select the printer.
(-1 = default printer)

Black Death.
0
 
LVL 1

Expert Comment

by:BlackDeath
Comment Utility
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
Comment Utility
same problem here.
0
 

Author Comment

by:lhlplmy
Comment Utility
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
Comment Utility
lhlplmy,

 Is everything working now?

Zif.
0
 

Author Comment

by:lhlplmy
Comment Utility
zif,
thank you .It's ok now.


0
 
LVL 8

Accepted Solution

by:
ZifNab earned 90 total points
Comment Utility
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
Comment Utility
Adjusted points to 90
0
 

Expert Comment

by:glabax
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now