canvas visibility changes at runtime

To make a canvas visible or invisible you just need to change the visible property or is there something else to do ?
because in my code below, setting the canvas1.visible=TRUE doesnt have any effect at all

any ideas ? thanks in advance

window1.canvas1.Visible=false ' hide before stretching n resizing canvas
  Dim picFile as FolderItem
  picFile=GetFolderItem (app.ImgFolder+f)           ' imgfolder+f = img file path
  Dim pic As Picture
  pic = Picture.Open(picFile)
  if pic =nil then
    msgbox "Bad pic !"
    ' stretching n resizing code goes here
    ElasticPict pic, window1.Canvas1
    window1.canvas1.visible=true' eve if it's true the canvas remains invisible  !!!!!
  end if

You MUST apply all changes to a CANVAS in its own PAINT event… changes outside this event are deprecated and produce unknown (if any) results)

Unless this code is in a thread that yields time back to the display, the effect of toggling visibility won’t show up. Basically, your entire method executes and then the display updates.

So if i want to change any proprieties of a canvas I have to do it from inside its paint event ??
How do I call this event ?
And what if this event raises during runtime and I dont need any changes to the canvas anymore?


No, you call Invalidate() after you have set the property.

  • Invalidate() tells the OS to raise the Paint event the next time the OS is drawing.
  • Refresh() and RefreshRect() are immediately calling the Paint event (usually it should not be necessary not use these)

Have a guard clause at the beginning of the Paint event.

I neeed to have a pic centered and proportiannly stretched on screen even when the user resizes and moves the window.
Maybe imagewell is easier/faster ?

No, an imagewell is worse. Use a canvas if you need it to respond to resizing.

Does canvas.visible=on/off calls the canvas paint event ?!?!?!? it seems so

Canvas.Invalidate() is what you need. It raises the Paint event.