Canvas Overlay%

I have a problem while trying to draw a canvas GUI element.

I create a frame, canvas and try to draw the context of the canvas context using the method draw-line, but nothing happens. A canvas frame is displayed, but the line is not displayed on the canvas.

(require racket/gui/base)

(define frame (new frame% [label "Frame"] [width 500] [height 500]))
(define canvas (new canvas% [parent frame]))
(define dc (send canvas get-dc))

(send dc draw-line 10 10 200 200)
(send frame show #t)

Does anyone know where I am mistaken in the code above?

+5
source share
2 answers

Try the following:

(require racket/gui/base)

(define frame (new frame% [label "Frame"] [width 500] [height 500]))
(define canvas (new canvas% [parent frame]))
(define dc (send canvas get-dc))

(send frame show #t)
(sleep/yield 1)
(send dc draw-line 10 10 200 200)

It seems you need to show the frame first, and then wait a bit until the window is ready.

+2
source

, , . , (, ), .

: paint.

#lang racket
(require racket/gui/base)

(define frame (new frame% [label "Frame"] [width 500] [height 500]))
(define canvas (new canvas% 
                    [parent frame]
                    [paint-callback 
                     (λ(can dc) (send dc draw-line 10 10 200 200))]))
(define dc (send canvas get-dc))
(send frame show #t)

. .

+5

All Articles