graphic.drawText

This is very strange.

I am using graphics.DrawText to draw into a canvas or a PDFDocument.

If I get the text from database (sqlite), the string does not appear in the canvas (I have it showing on the screen). If I hard code a value (instead of getting the value from the database), it works.

I put exclamation points around the word in question (i.e. !Sunday!). Stepping through the code I can see it’s correct at the call to g.DrawText. What appears on the screen is just !!

It works correctly when writing to the PDFDocument.

Anyone have any clue? I find this very strange.

It could be that the string in the database contains control characters such as &h00 which is preventing DrawText from working correctly.

You should be able to the check this by viewing the string in the debugger and choosing the binary data view.

Had checked that. I just see normal looking codes.

Wrote some stuff to a text file.

The value from the database did not appear (it looks correct in the debugger).

Could it be an encoding issue?

That was my first thought.

Checking in the debugger, it indicates that it’s UTF8.

Explicitly converting it made no difference.

But did you define the encoding when you read it from the database? Otherwise it will be incorrect. Unless you defined it, the debugger is lying to you.

Problem solved.

What I was doing: I was generating the stuff to show by writing to the graphics object of a DesktopCanvas. During the Canvas paint event. What I didn’t realize was that the paint event may get called more than once as the window appears. Since we only see the results of the latest call, the database had run out of rows, and no value was returned. Of course using the debugger didn’t help as it was invoked on the first call.

What I am now doing: Now drawing to the graphics object of a picture. The picture is then drawn to the screen. It does not get changed from multiple paint events.

Hope this help some one.

I am going to take a break (not break into the debugger).