As long as you're "printing" the Delphi way, you'll be using a TCanvas
rather you're printing on a real printer OR onto a bitmap; As a matter of
fact, there's NO difference betwen drawing on a bitmap or printing to a
printer.
On a form put 2 buttons and a CheckListBox; Button1 will be labeld "Print on
bitmap" while Button2 will be called "Print on printer"; You'll also need to
add a "DoPrint" procedure that takes one TCanvas parameter; This routine
will be used to "print" the CheckListBox on the printer OR on the bitmap!
You may use this routine and experiment a bit
P.S: Are you sure a CheckListBox with 100 items is a good option?
<code>
procedure TForm1.FormCreate(Sender: TObject);
var i:Integer;
begin
Randomize;
for i:=1 to 30 do
begin
CheckListBox1.Items.Add('Line no #' + IntToStr(i));
CheckListBox1.Checked[i-1] := (Random(5) mod 2) = 0;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var B:TBitmap;
begin
B := TBitmap.Create;
try
B.Height := 100;
B.Width := 100;
DoPrint(B.Canvas);
B.SaveToFile('C:\Temp\Test.bmp');
finally B.Free;
end;
end;
procedure TForm1.DoPrint(C: TCanvas);
var i:Integer;
s:string;
c_top:integer;
text_h:Integer;
begin
c_top := 0;
// Basic font options
C.Font.Name := 'Arial';
C.Font.Size := 10;
// Pen options (for checkboxes)
C.Pen.Width := 1;
C.Pen.Color := clBlack;
C.Pen.Style := psSolid;
for i:=0 to CheckListBox1.Items.Count-1 do
begin
if CheckListBox1.Checked[i] then
begin
// Prepare printing for a "checked" item
C.Font.Style := [fsBold];
C.Font.Color := clRed;
end
else
begin
// Prepare printing for a "unchecked" item
C.Font.Style := [];
C.Font.Color := clNavy;
end;
// Calculate the height for our next line of text
text_h := C.TextHeight(s);
// Draw a "checkbox"
C.Rectangle(2, c_top, text_h-4, c_top + text_h-4);
if CheckListBox1.Checked[i] then
begin
C.MoveTo(4, c_top+4);
C.LineTo(text_h-8, c_top + text_h-8);
C.MoveTo(text_h-8, c_top+4);
C.LineTo(4, c_top + text_h -8);
end;
// Draw the text
s := CheckListBox1.Items[i];
C.TextOut(text_h, c_top, s);
c_top := c_top + text_h; // Advance to next line
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Printer.BeginDoc;
try
DoPrint(Printer.Canvas);
finally Printer.EndDoc;
end;
end;
</code>
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:delphi-talk-
> [EMAIL PROTECTED] On Behalf Of M Tuttle
> Sent: Tuesday, December 13, 2005 8:12 AM
> To: Delphi-Talk Discussion List
> Subject: Re: Printing Items in a TCheckListBox
>
> Hi Stephen,
>
> The CheckListBox may contain several hundred items. Therefore printing a
> canvas is not what I want to do. I would much rather iterate thought the
> list and print a small bitmap representing a checked or unchecked check
> box
> followed by the text of the TCheckListBox item. Any examples of how I
> could
> to do that?
>
> Mike
>
> ----- Original Message -----
> From: "Stephen Posey" <[EMAIL PROTECTED]>
> To: "Delphi-Talk Discussion List" <[email protected]>
> Sent: Monday, December 12, 2005 3:28 PM
> Subject: Re: Printing Items in a TCheckListBox
>
>
> > M Tuttle (KS) wrote:
> >
> > > Greetings All,
> > >
> > > Doe anyone have any code snippet they could share that would allow me
> to
> > > print all items in a TCheckListBox and maybe show a difference between
> the
> > > items that are checked in the list versus those that are not checked.
> Maybe
> > > bold type for selected? Any ideas at all would be appreciated.
> >
> > Probably the simplest thing to do is copy the TCheckListBox's
> > canvas to the printer canvas or a bitmap's canvas as part of
> > setting up your printout.
> >
> > E.g.:
> >
> > Printer.Canvas.CopyRect( Rect(0, 0, 1500, 1500),
> > CheckListBox1.Canvas,
> > Rect( 0, 0, CheckListBox1.Width, CheckListbox1.Height ));
> >
> > If you need to have the text match up with other text in the
> > printout, you'll need to iterate the CheckListbox and build your
> > text based on its contents before adding it to the printout using
> > DrawText or whatever.
> >
> > If you can give a little more background on how you're setting up
> > the printing, I can probably be more precise.
> >
> > HTH
> >
> > Stephen Posey
> > [EMAIL PROTECTED]
> >
> > __________________________________________________
> > Delphi-Talk mailing list -> [email protected]
> > http://www.elists.org/mailman/listinfo/delphi-talk
> >
>
>
> __________________________________________________
> Delphi-Talk mailing list -> [email protected]
> http://www.elists.org/mailman/listinfo/delphi-talk
__________________________________________________
Delphi-Talk mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi-talk