Timer In Canvas - Won't Activate Depending on Invalidate Location

I have a strange issue.
I’ve subclassed a canvas and I’m trying to emulate a textbox, therefore using a timer to create a blinking cursor.

I have a timer(xojo.core.timer) as a private property of the canvas, the class’s constructor sets it up, adds the handler. Then, a mouse click down event will change the timer’s mode to multiple… should start the timer.

The handler simply flips a boolean value and then calls a method which draws the textbox with or without the cursor to a picture, Then, invalidate is called to Paint the picture.

Sub Handler(myTimer as Xojo.Core.Timer) show = not show DrawTextBox //invalidate end sub

If Invalidate is called from the Handler it works

If Invalidate is called inside DrawTextBox it seems to kill the timer.

Sub DrawTextBox() Buffer = new picture(width, height) dim g as Graphics g = Buffer.Graphics g.Draw... //do stuff if show then //draw cursor... end if invalidate //this here seems to mess up the timer end sub
Strange and Frustrating.

Lastly, I created a dumbed down version to try to reproduce it. Making the same calls and the same code flow. I can’t reproduce the behavior.

Any tips on how else to debug this?

Don’t call Invalidate or Refresh from a Paint event or any methods that are called from it (drawing code). You’ll potentially get yourself into an endless loop depending on how aggressively it redraws.

Hey Greg, I see what you’re saying, and I think that’s the issue, but my main drawing code is not in the paint event as I buffer to a picture and then paint the picture.

Something in my drawing code is invalidating the canvas.

What else can trigger the paint event?

What version of Xojo are you using?
What does your paint event look like?

Thanks all for the provocative comments. I found that my Paint Event was calling a redundant method which was calling Invalidate

Problem solved.