thank you very much<div>the following code works well</div><div><div>===================================================</div><div>#lang scheme/gui</div><div>(require 2htdp/image)</div><div>(define pic dc<%>)</div><div>
(define chipset (make-object bitmap% "town.png" 'png))</div><div>(define f (instantiate frame% ("map editor")))</div><div>(define mcan% </div><div> (class canvas%</div><div> </div><div> (override on-event on-paint)</div>
<div> (define on-paint</div><div> (λ () (send (send this get-dc) draw-bitmap chipset 0 0)))</div><div> (define on-event (λ (e) </div><div> (send msg set-label </div><div> (string-append (number->string (send e get-x)) " " </div>
<div> (number->string (send e get-y))))))</div><div> (super-instantiate ())))</div><div><br></div><div>(define mcan (new mcan% (parent f) (min-width (image-width chipset)) (min-height (image-height chipset))))</div>
<div><br></div><div>(define msg (instantiate message% ("nothing so far" f)))</div><div>(send f show #t)</div><div>===================================================</div><br><div class="gmail_quote">2010/10/27 Ryan Culpepper <span dir="ltr"><<a href="mailto:ryanc@ccs.neu.edu">ryanc@ccs.neu.edu</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div></div><div class="h5">김태윤 wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
drawing on canvas what's wrong with my code?<br>
<br>
I coded as follow and run it but nothing apear.<br>
could sombody tell me what's wrong with my code?<br>
<br>
#lang scheme/gui<br>
(require 2htdp/image)<br>
(define pic dc<%>)<br>
<br>
(define f (instantiate frame% ("map editor")))<br>
(define mcan%<br>
(class canvas%<br>
<br>
(override on-event)<br>
<br>
(define on-event (λ (e)<br>
(send msg set-label<br>
(string-append (number->string (send e get-x)) " "<br>
(number->string (send e get-y))))))<br>
(super-instantiate ())))<br>
<br>
(define mcan (new mcan% (parent f) (min-width 400) (min-height 400)))<br>
(send (send mcan get-dc) draw-bitmap (make-object bitmap% "town.png"<br>
'png) 16 16)<br>
<br>
(define msg (instantiate message% ("nothing so far" f)))<br>
(send f show #t)<br>
</blockquote>
<br></div></div>
A plain canvas% doesn't remember what's drawn to it. In your code, you're drawing to the canvas before the frame is visible, and by the time the canvas is shown it has forgotten what you've drawn on it.<br>
<br>
The code that draws on the canvas's dc should be inside the canvas's on-paint method:<br>
<br>
(class canvas%<br>
...<br>
(define/override (on-paint)<br>
(send (send this get-canvas) draw-bitmap the-bitmap 16 16)<br>
(super on-paint))<br>
...)<br><font color="#888888">
<br>
Ryan<br>
</font></blockquote></div><br></div>