Solved

How can i Print TListBox

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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

15 Experts available now in Live!

Get 1:1 Help Now