Solved

How can i Print TListBox

Posted on 2001-08-08
4
271 Views
Last Modified: 2010-04-06
hi
if some one give me example how i print Tlistbox
or something close , i know that i need to use PrintDialog
thank

0
Comment
Question by:krelman
  • 2
4 Comments
 

Expert Comment

by:lbseong
ID: 6364502
yup u have to use the printdialogbox...and u also can use the quick report preview to view ur report and do the printing...
0
 
LVL 5

Accepted Solution

by:
alanwhincup earned 100 total points
ID: 6364633
You could do it like this:

procedure TForm1.Button1Click(Sender: TObject);
var
  Temp : TRichEdit;
begin
  if PrintDialog1.Execute then
  begin
    Temp := TRichEdit.CreateParented(Handle);
    Temp.Lines := ListBox1.Items;
    Temp.Print('LPT1');
    Temp.Free;
  end;
end;

Cheers,

Alan
0
 
LVL 5

Expert Comment

by:alanwhincup
ID: 6364645
Forgot to say that you have to remeber to add 'ComCtrls' to the uses clause of the unit.
0
 
LVL 21

Expert Comment

by:gemarti
ID: 6364711
This literally prints the listbox!
Create a new Application
Put a List box on the form and add some strings.
ListBox1.MultiSelect := true;

Put a button on the form

Add this unit in place of the delphi created unit:

--------------cut below line ----------------------

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,Printers;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    Button1: TButton;
    PrintDialog1: TPrintDialog;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  i, Start, Stop : Integer;
begin
PrintDialog1.Options := [poPageNums, poSelection];
PrintDialog1.FromPage := 1;
PrintDialog1.MinPage := 1;
PrintDialog1.ToPage := ListBox1.Count;
PrintDialog1.MaxPage := ListBox1.Count;
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 := ListBox1.Items.Count;
        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
        ListBox1.PaintTo(Printer.Handle,10,10);
      if I <> Stop then
          NewPage;
      end;
      EndDoc;
    end;
  end;

end;

end.

---------------Cut above line --------------------

If you want to print in readable text you may want to try:
ListBox1.Items.SaveToFile(FileName.txt)

Then retrieve the text file and print it.
 
 
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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 my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 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

14 Experts available now in Live!

Get 1:1 Help Now