Solved

How can i Print TListBox

Posted on 2001-08-08
4
278 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
[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
  • 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

733 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