Line numbering problem

I have a textarea with next to it a canvas

code: canvas1.paint
g.TextFont = editarea.TextFont
g.TextSize = editarea.Textsize
g.ForeColor = rgb(100,100,250)
g.bold = true

dim x as integer
dim th as integer
th =g.StringHeight(“0”,300)

for x = 0 to editarea.height/th
g.DrawString format (x+editarea.scrollposition,“0”), 2, x * th + editarea.top
next

canvas1.Refresh

This shows a linenumbering next to the textarea. This works in Xojo 2018r3, but no more in 2019r2 (the lines don’t scroll anymore).
What is going wrong?

Is canvas1.Refresh part of the Paint event? If so, take it out.

Taking out canvas1.reresh didn’t change anything. In fact it doesn’t also work now on 2018r3

I saw that g.drawstring is deprecated. Anyone an idea how solve this?

Use g.drawtext instead, like the doc page says.

Could you help me with the code?

Using g.drawtext did not solve the problem

The problem is that the portion x * th + editarea.top returns a global coordinate, not one local to the canvas so the printing likely takes place below the canvas. You need to either calculate the Y position local to the canvas or adjust it with something like (example, not recommended)

g.DrawString (format (x + ta2.scrollposition, "0"), 2, (x * th + ta2.top)- me.top)

I think that this code works in Xojo 2018 because you was always updating the canvas1.
It must have made the processor warm up…
The problem is that TextArea has no event to know when the scroll position changes.
Put “Canvas1.Refresh” in SelChange" and “MouseWheel” of TextArea is not enough.

If you call “Canvas1.Refresh” in a timer, that works but it is not very good!

You could track the scroll position and only redraw if it’s changed. That would make the timer more efficient.