Print background when no text lines…

I implemented a simple (set to 2 columns only) Print ListBox Contents in colours yesterday and fall into a trap.

I used the ListBox CellBackground… example code ( expanded to two Rows):

[code]If row Mod 2 = 0 Then
g.ForeColor = &cf3f6fA
Else
g.ForeColor = &cfAf6f3
End If

g.FillRect(0, 0, g.Width, g.Height)[/code]

Then, I print the context of the two columns (columns 0 and 1)

I get what I wanted with a simple minus: the last page or the part of the page without text is printed with the last used color…

I suppose it is the last used color (vary if the last line is Odd or Even) because I get the same color in the non text part and the last text printed line.

Any idea ?

Nice to get the pdf with background colors !

Here’s an example (with cyan, but I have other examples with yellow):

I cut the screen shot, so the footer line is not displayed…

Hi Emile,

I believe you are handling all the printing yourself.
So you could easily stop drawing the color as soon as all Listbox rows have been printed. And even reset the color to white if necessary.

Hi Jrmie,

while your answer (thank you for it) ring some unknow bell, I checked to set the color to white (or black), but I still get one of the two colors filled the page.

In that check, I tested if there is a string to print (using If Cell(LoopIdx,0) = Nil then), bug the “bug” was still here.

I may set a boolean (EndOfPrint for example) to True when the last Row to print is reached and exit the loop from there. IT may be that who was ringing in my head. I will try that this afternoon.

BTW: that is what you wrote ! OK, I memorize the beginning of the line and forgot starting at “as soon as all Listbox rows”…

Thanks.

Yes.

Note: the alternate colours are stored in two globals and can be changed in a Preferences window, saved / loaded to/from a file. So any displayed color will be used at print time. I only have to add the “print all columns from the ListBox” feature and I will be done. As is, it can be used in a fixed number of columns (two or three and these values have to be known before compiling the application). So for two current projects, I already added the feature because they have a fixed number of Columns.