Solved

How can i Print TListBox

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Syntax Check Delphi Seattle IOS app without MAC ? 1 97
Magic Software info 18 130
delphi parse string to params 3 122
TEMBEDDEDWB how can i change its user agent ? 8 58
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 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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

786 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