Canvas Invalidate

I have a Canvas subclass with two properties: Tiling and Scaling. In the Paint event:

[code]Sub Paint(g As Graphics, areas() As REALbasic.Rect) Handles Paint

If Scaling Then
Me.Backdrop = ScalePic(Graphic, Me.Width, Me.Height, 2)
ElseIf Tiling Then
Me.Backdrop = New Picture(Me.width, Me.Height, 32)
For i As Integer = 0 To Me.Width Step Graphic.Width
For j As Integer = 0 To Me.Height Step Graphic.Height
Me.Backdrop.Graphics.DrawPicture(Graphic, i, j)
Next
Next
End If[/code]

Picture is in the ‘Graphic’ property.
But the Canvas doesn’t show anything unless I force an event like resizing the Window. Adding a Me.Invalidate doesn’t change anything.
How come?

End Sub

I think that the Backdrop is actually drawn just before calling Paint, so you end up with the old backdrop.

You should actually draw the backdrop you want yourself, instead of setting the Backdrop variable, with g.DrawPicture

Don’t alter anything inside a Paint event, only draw. You need to figure out some other logic to set up the backdrop correctly.

http://documentation.xojo.com/topics/user_interface/desktop/desktop_controls/canvas.html#canvas-backdrop

Why not just draw the Graphic to the canvas directly instead of using Backdrop? Seems like you’re doing too much work.

a. What is Graphic ?

b. Your loop step Graphic.Width ?

c. You create a New Picture, but do not check if it is valid.

d. Use a Picture variable tos tore the data in and then,

e. If the Picture vraiable is not Nil, assign it to the Canvas.Backdrop

Result: ?