Solved

How can i Print TListBox

Posted on 2001-08-08
4
277 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…

792 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