绘制到canvas%元素 [英] Drawing onto canvas% element
本文介绍了绘制到canvas%元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在尝试绘制到画布GUI元素时遇到问题。
我创建了一个框架,一个画布,并尝试在画布的直流上下文与 draw-line
方法,但没有任何反应。显示了带有画布的框架,但线条未在画布上显示。
(需要球拍/ gui / )
(定义框架(新框架%[标签框架] [宽度500] [高度500]))
b $ b(定义dc(发送画布get-dc))
(发送直流绘制线10 10 200 200)
(发送帧显示#t)
<有没有人知道我在上面的代码中错了什么? >解决方案试试这个:
(需要racket / gui / base)
(定义框架(新框架%[标签框架] [宽度500] [高度500]))
(定义画布(新画布%[父框架]))
(发送画布get-dc))
(发送帧显示#t)
(sleep / yield 1)
(发送直流绘制线10 10 200 200)
看起来你需要先显示框架,然后等待一下让窗口准备好。 / p>
I have a problem while trying to draw onto a canvas GUI element.
I create a frame, a canvas and try to draw on the dc context of the canvas with the draw-line
method, but nothing happens. The frame with the canvas is shown, but the line isn't shown 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 anybody know where I am wrong in the code above ?
解决方案 Try this:
(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 that you need to show the frame first and then wait a bit to let the window get ready.
这篇关于绘制到canvas%元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文