<div dir="ltr"><div><div><div><div><div>I would like to draw on a canvas in a window at various times during program execution. <br></div>My first attempt was to combine two examples:<br><br>#lang racket/gui<br><br>(define frame (new frame%<br>                   [label "Example"]<br>                   [width 300]<br>                   [height 300]))<br>(define top-canvas (new canvas% [parent frame]))<br><br>(send frame show #t)<br><br>(define dc (send top-canvas get-dc))<br><br>(send dc draw-rectangle<br>      0  10   ; Top-left at (0, 10), 10 pixels down from top-left<br>      30 10) ; 30 pixels wide and 10 pixels high<br>(send dc draw-line<br>      0 0    ; Start at (0, 0), the top-left corner<br>      30 30) ; and draw to (30, 30), the bottom-right corner<br>(send dc draw-line<br>      0 30   ; Start at (0, 30), the bottom-left corner<br>      30 0)  ; and draw to (30, 0), the top-right corner<br><br>                      <br><br></div>The cross and box are drawn, but "instantly" over-written by a blank canvas. I suppose this is because on-paint is triggered? (not sure by what..)<br></div>If I put the (send frame...) form at the end of the code, the cross and box aren't seen.<br><br></div>I am sure this is due to me not understanding the model properly - I'd be grateful for some help...<br><br></div>many thanks<br><br>Chris<br></div>