# canvas visibility changes at runtime

**URL:** <https://forum.xojo.com/t/canvas-visibility-changes-at-runtime/18389>\
**Category:** Getting Started\
**Created:** [August 5, 2014, 4:22pm UTC](https://forum.xojo.com/t/canvas-visibility-changes-at-runtime/18389 "2014-08-05T16:22:07Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Horacio\_Vilches](https://forum.xojo.com/letter_avatar_proxy/v4/letter/h/ad7895/32.png) [@Horacio\_Vilches](https://forum.xojo.com/u/Horacio_Vilches)\
**Post date:** [August 5, 2014, 4:22pm UTC](https://forum.xojo.com/t/canvas-visibility-changes-at-runtime/18389/1 "2014-08-05T16:22:07Z")

</div>

Hi  
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

```auto

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 !"
  
else
    ' 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

```

---

<div class="post-metadata">

**Author:** ![DaveS](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@DaveS](https://forum.xojo.com/u/DaveS)\
**Post date:** [August 5, 2014, 4:27pm UTC](https://forum.xojo.com/t/canvas-visibility-changes-at-runtime/18389/2 "2014-08-05T16:27:17Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [August 5, 2014, 6:48pm UTC](https://forum.xojo.com/t/canvas-visibility-changes-at-runtime/18389/3 "2014-08-05T18:48:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Horacio\_Vilches](https://forum.xojo.com/letter_avatar_proxy/v4/letter/h/ad7895/32.png) [@Horacio\_Vilches](https://forum.xojo.com/u/Horacio_Vilches)\
**Post date:** [August 6, 2014, 7:07am UTC](https://forum.xojo.com/t/canvas-visibility-changes-at-runtime/18389/4 "2014-08-06T07:07:47Z")

</div>

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?

Thanks

---

<div class="post-metadata">

**Author:** ![Eli\_Ott](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@Eli\_Ott](https://forum.xojo.com/u/Eli_Ott)\
**Post date:** [August 6, 2014, 8:11am UTC](https://forum.xojo.com/t/canvas-visibility-changes-at-runtime/18389/5 "2014-08-06T08:11:02Z")

</div>

> [@117862:@Horacio Vilches](#):
>
> So if i want to change any proprieties of a canvas I have to do it from inside its paint event ??

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

> [@117862:@Horacio Vilches](#):
>
> How do I call this event ?

- 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)

> [@117862:@Horacio Vilches](#):
>
> And what if this event raises during runtime and I dont need any changes to the canvas anymore?

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

---

<div class="post-metadata">

**Author:** ![Horacio\_Vilches](https://forum.xojo.com/letter_avatar_proxy/v4/letter/h/ad7895/32.png) [@Horacio\_Vilches](https://forum.xojo.com/u/Horacio_Vilches)\
**Post date:** [August 6, 2014, 8:27am UTC](https://forum.xojo.com/t/canvas-visibility-changes-at-runtime/18389/6 "2014-08-06T08:27:10Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [August 6, 2014, 9:01am UTC](https://forum.xojo.com/t/canvas-visibility-changes-at-runtime/18389/7 "2014-08-06T09:01:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Horacio\_Vilches](https://forum.xojo.com/letter_avatar_proxy/v4/letter/h/ad7895/32.png) [@Horacio\_Vilches](https://forum.xojo.com/u/Horacio_Vilches)\
**Post date:** [August 10, 2014, 3:26pm UTC](https://forum.xojo.com/t/canvas-visibility-changes-at-runtime/18389/8 "2014-08-10T15:26:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Ashot\_Khachatryan](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@Ashot\_Khachatryan](https://forum.xojo.com/u/Ashot_Khachatryan)\
**Post date:** [August 10, 2014, 4:02pm UTC](https://forum.xojo.com/t/canvas-visibility-changes-at-runtime/18389/9 "2014-08-10T16:02:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 5:21pm UTC](https://forum.xojo.com/t/canvas-visibility-changes-at-runtime/18389/10 "2020-10-29T17:21:43Z")

</div>


